[resolved] Show a div when having a determined shipping class (5 posts)

  1. vtrlvz
    Posted 2 years 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!


  2. vtrlvz
    Posted 2 years ago #

    Anyone could help me, please?

  3. customdesign
    Posted 2 years 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() ) : ?>

    $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
    Posted 2 years 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
    Posted 2 years ago #

    Worked perfectly, thank you so much!

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • WooCommerce
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic


No tags yet.