删除特定产品标签的库存状态 - Woocommerce

Remove stock status for specific product tag - Woocommerce

我试图仅在产品标记为 'preorder' 时才在单个产品页面上隐藏库存状态。

到目前为止,我已将下面提到的代码添加到我的 functions.php 中,以更改此特定标签的添加到购物车按钮文本。知道要添加什么代码 should/could 才能实现此目的吗?

//For single product page
add_filter( 'woocommerce_product_single_add_to_cart_text', 'woo_custom_cart_button_text' ); // 2.1 +
function woo_custom_cart_button_text() {
    global $product;
    if ( has_term( 'Preorder', 'product_tag', $product->ID ) ) :
        return __( 'Pre order Now !', 'woocommerce' );
else:
        return __( 'In Winkelmand', 'woocommerce' );
    endif;
}

您应该为此目的尝试 woocommerce_stock_html 过滤器钩子:

add_filter( 'woocommerce_stock_html', 'filter_woocommerce_stock_html', 10, 3 ); 
function filter_woocommerce_stock_html( $availability_html, $availability_availability, $variation ) { 
    global $product;
    if ( has_term( 'Preorder', 'product_tag', $product->ID ) ) :
        // Define here your text to replace
        $availability_html = __( 'Say something here', 'woocommerce' );
    endif;

    return $availability_html; 
};  

此代码已经过测试,希望是您所期望的。

代码进入您的活动子主题(或主题)的 function.php 文件。或者在任何插件 php 文件中。