Wim*_*Wim 5 php wordpress product stock woocommerce
我只是在产品标有"预订单"时,试图隐藏单个产品页面上的库存状态.
到目前为止,我已经将下面提到的代码添加到我的functions.php中,以更改此特定标记的"添加到购物车"按钮文本.知道应该/可以添加什么代码才能实现这一目标吗?
//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;
}
Run Code Online (Sandbox Code Playgroud)
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;
};
Run Code Online (Sandbox Code Playgroud)
这段代码已经过测试,我希望是您所期望的。
代码位于活动子主题(或主题)的 function.php 文件中。或者也可以在任何插件 php 文件中。
| 归档时间: |
|
| 查看次数: |
591 次 |
| 最近记录: |