Advertisement
lorro

WooCommerce - Exclude stock amount for one category

Sep 23rd, 2015
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.52 KB | None | 0 0
  1. <?php
  2. // exclude stock amount for one category
  3. // code goes in functions.php for your child theme
  4. function shop_inventory() {
  5.   global $product;
  6.   $terms = get_the_terms( $product->post->ID, 'product_cat' );
  7.   $show = true;
  8.   foreach ($terms as $term) {
  9.     if ($term->term_id == 12) { // where 12 is your cat id for service
  10.       $show = false;
  11.     }
  12.   }
  13.   if ($show) {
  14.     echo 'Available: '.number_format($product->stock,0,'','');
  15.   }
  16. }
  17. add_action( 'woocommerce_after_shop_loop_item_title', 'shop_inventory' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement