更新“销售!” Woocommerce中的变量产品从“缺货”更改为“缺货”

时间:2020-04-07 21:32:10

标签: variables woocommerce badge

当所有版本都缺货时,是否可以修改代码以使其适用于可变产品?

// Add badge  "Out of stock" (and replace sale badge)

    add_action('woocommerce_before_shop_loop_item_title','custom_before_shop_loop_item_title', 2 ); 
    function custom_before_shop_loop_item_title(){
        remove_action('woocommerce_before_shop_loop_item_title','woocommerce_show_product_loop_sale_flash', 10 );
        remove_action('woocommerce_after_shop_loop_item_title','woocommerce_show_product_loop_sale_flash', 6 ); // For storefront theme
        add_action('woocommerce_before_shop_loop_item_title','show_product_loop_outofstock_badge', 10 );
    }

    function show_product_loop_outofstock_badge(){
        global $post, $product;

        if ( $product->get_stock_status() == 'outofstock' ) :
            echo '<span class="onsale outofstock">'. esc_html__('Out of stock', 'woocommerce') .'</span>';
        elseif ( $product->is_on_sale() ) :
            echo '<span class="onsale">'. esc_html__( 'Sale!', 'woocommerce' ) .'</span>';
        endif;
    }

0 个答案:

没有答案