Custom code stock
-
Hi is there a way to display when stock is below 4 pcs text Only 4,3,2 lleft in stock in this code, and when is only one to display last in stock?
thank you
//* Add stock status to archive pages function envy_stock_catalog() { global $product; //check the variable products if ( $product->get_type() == 'variable' ) { foreach ( $product->get_available_variations() as $key ) { $attr_string = array(); foreach ( $key['attributes'] as $attr_name => $attr_value ) { $attr_string[] = $attr_value; } if ( $key['max_qty'] > 0 ) { $var_result = true; } else { $var_result = false; } } } //var_dump($var_result); //var_dump($product->get_available_variations()); if ( ($product->is_in_stock() && $product->get_stock_quantity() > 0) || $var_result == true ) { echo '<div class="stock" >' . __( ' Skladom', 'envy' ) . '</div>'; } elseif($product->is_in_stock() && $product->get_stock_quantity() < 1) { echo '<div class="stock stock-order-only" >' . __( ' Na objednávku', 'envy' ) . '</div>'; } else { echo '<div class="out-of-stock" >' . __( 'Nie je na sklade', 'envy' ) . '</div>'; } } add_action( 'woocommerce_after_shop_loop_item_title', 'envy_stock_catalog' );
The page I need help with: [log in to see the link]
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Custom code stock’ is closed to new replies.