daily pastebin goal
32%
SHARE
TWEET

WooCommerce - Exclude stock amount for one category

lorro Sep 23rd, 2015 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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' );
RAW Paste Data
Top