Support » Plugin: WooCommerce » Show a div when having a determined shipping class

  • Resolved vtrlvz

    (@vtrlvz)


    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/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Anyone could help me, please?

    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>';
    }
    ?>

    🙂

    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

    Worked perfectly, thank you so much!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Show a div when having a determined shipping class’ is closed to new replies.