WordPress.org

Ready to get started?Download WordPress

Forums

WooCommerce - excelling eCommerce
[resolved] Show a div when having a determined shipping class (5 posts)

  1. vtrlvz
    Member
    Posted 9 months ago #

    Hi guys, i'm new here.

    Well, i'm trying to add a filter that shows a div on the product catalog when a product matches with a determined shipping class, but have no idea how to do that.

    For example: I'm selling the most of products by drop shipping, but I have a few to send immediately, so I created a shipping class called "In Stock", and set those to that class. I want to a div element written "IN STOCK" shows up on the product catalog, right after the price of the product that has the determined shipping class.

    Well, it's just it... thank you!

    http://wordpress.org/plugins/woocommerce/

  2. vtrlvz
    Member
    Posted 8 months ago #

    Anyone could help me, please?

  3. customdesign
    Member
    Posted 8 months ago #

    This is what I would do: search for the template files price.php, (wp-content/plugins/woocomerce/templates/ loop and single-product) copy both of them into your theme's folder in a new folder woocommerce/loop/ and woocommerce/single-product. Edit them and put the code below right after the following statement: <?php if ( $price_html = $product->get_price_html() ) : ?>

    <?php
    $term = get_term( $product->get_shipping_class_id() , 'product_shipping_class' );
    if ($term->name=='IN STOCK'){
    echo '<div class="your-class">'.$term->name.'</div>';
    }
    ?>

    :)

  4. Colin Young
    Member
    Posted 8 months ago #

    The only thing I would add to this and that would protect you from future updates, would be to do this in a child theme.

    PHP code is susceptible to being removed by updates and WooCommerce offer excellent child theme options out of the box

  5. vtrlvz
    Member
    Posted 8 months ago #

    Worked perfectly, thank you so much!

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.