我想仅在 specific categories 上更改产品档案中的添加到购物车文本 . 例如,在 preorder category 上我想要而不是 add to cart
文本,是 Preorder
. 我不知道如何 identify Preorder category 在下面的功能 .
add_filter( 'add_to_cart_text', 'woo_archive_custom_cart_button_text' ); // < 2.1
function woo_archive_custom_cart_button_text() {
return __( 'Preorder', 'woocommerce' );
}
2 回答
您可以在条件中使用has_term() . 更新后的代码如下 .
Solution- 1. Using filter add_to_cart_text
Solution- 2. Using filter woocommerce_product_add_to_cart_text
其中
your-special-category
将是您要替换的类别add to cart
文本 .它可以是两个不同的东西(因为你的问题不是那么清楚)......
1)要定位产品 on a specific product category archive pages ,您应该使用条件函数is_product_category()这样:
代码位于活动子主题(或活动主题)的function.php文件中 .
2)要在Woocommerce存档页面上定位特定产品类别,您将以这种方式使用has term():
对于单个产品页面,您将另外使用此:
代码位于活动子主题(或活动主题)的function.php文件中 .
经过测试和工作 .
相关回答:Targeting product terms from a custom taxonomy in WooCommerce
相关文档:Woocommerce Conditional Tags