Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action( 'woocommerce_after_shop_loop_item_title', 'woowoo_category_stock', 20 );
- //add_action( 'woocommerce_after_shop_loop_item', 'woowoo_category_stock', 20 );
- function woowoo_category_stock() {
- global $product;
- if ( $product->get_type() == 'simple' ) {
- $stockquantity = $product->get_stock_quantity();
- if ( $stockquantity >= 3) {
- echo '<div class="woowoo_green"><i class="fa fa-square" aria-hidden="true" title="3 kusy"></i> - 3 kusy</div>';
- }
- elseif ( $stockquantity >= 2 ) {
- echo '<div class="woowoo_yellow"><i class="fa fa-square" aria-hidden="true" title="2 kusy"></i> - 2 kusy</div>';
- }
- else {
- echo '<div class="woowoo_red"><i class="fa fa-square" aria-hidden="true" title="poslední kus"></i> - poslední kus</div>';
- }
- } else if ( $product->get_type() == 'variable' ) {
- foreach ( $product->get_available_variations() as $key ) {
- foreach ( $key['attributes'] as $attr_name => $attr_value ) {
- if ( $key['max_qty'] >= 3 ) {
- echo '<div class="woowoo_green"><i class="fa fa-square" aria-hidden="true" title="3 kusy"></i> ' . $attr_value . ' - 3 kusy</div>';
- }
- elseif ( $key['max_qty'] >= 2 ) {
- echo '<div class="woowoo_yellow"><i class="fa fa-square" aria-hidden="true" title="2 kusy"></i> ' . $attr_value . ' - 2 kusy</div>';
- }
- else {
- echo '<div class="woowoo_red"><i class="fa fa-square" aria-hidden="true" title="poslední kus"></i> ' . $attr_value . ' - poslední kus</div>';
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement