Advertisement
Fany_VanDaal

Počet ks skladem v loopu

May 22nd, 2023
686
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.69 KB | None | 0 0
  1. add_action( 'woocommerce_after_shop_loop_item_title', 'woowoo_category_stock', 20 );
  2. //add_action( 'woocommerce_after_shop_loop_item', 'woowoo_category_stock', 20 );
  3.  
  4. function woowoo_category_stock() {
  5.     global $product;
  6.     if ( $product->get_type() == 'simple' ) {
  7.         $stockquantity = $product->get_stock_quantity();
  8.         if ( $stockquantity >= 3) {
  9.             echo '<div class="woowoo_green"><i class="fa fa-square" aria-hidden="true" title="3 kusy"></i> - 3 kusy</div>';
  10.         }
  11.         elseif ( $stockquantity  >= 2 ) {
  12.             echo '<div class="woowoo_yellow"><i class="fa fa-square" aria-hidden="true" title="2 kusy"></i> - 2 kusy</div>';
  13.         }
  14.         else {
  15.             echo '<div class="woowoo_red"><i class="fa fa-square" aria-hidden="true" title="poslední kus"></i> - poslední kus</div>';
  16.         }
  17.     } else  if ( $product->get_type() == 'variable' ) {
  18.         foreach ( $product->get_available_variations() as $key ) {
  19.             foreach ( $key['attributes'] as $attr_name => $attr_value ) {
  20.                  if ( $key['max_qty'] >= 3 ) {
  21.                     echo '<div class="woowoo_green"><i class="fa fa-square" aria-hidden="true" title="3 kusy"></i> ' . $attr_value . ' - 3 kusy</div>';
  22.                 }
  23.                 elseif ( $key['max_qty'] >= 2 ) {
  24.                     echo '<div class="woowoo_yellow"><i class="fa fa-square" aria-hidden="true" title="2 kusy"></i> ' . $attr_value . ' - 2 kusy</div>';
  25.                 }
  26.                 else {
  27.                     echo '<div class="woowoo_red"><i class="fa fa-square" aria-hidden="true" title="poslední kus"></i> ' . $attr_value . ' - poslední kus</div>';
  28.                 }
  29.             }
  30.  
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement