英文:
Woocommerce Change 'Select Options' button text for specific category
问题
我有以下更改可变产品的按钮文本的代码,从“选择选项”更改为“选择日期”。
add_filter('woocommerce_product_add_to_cart_text', 'change_select_options_button_text', 9999, 2);
function change_select_options_button_text($label, $product) {
if ($product->is_type('variable')) {
return '选择日期';
}
return $label;
}
我想将此代码仅应用于特定类别,而不是应用于每个可变产品。这是否可能?
我尝试添加以下内容:if ( is_product_category('cat1')
但是没有成功。
add_filter('woocommerce_product_add_to_cart_text', 'change_select_options_button_text', 9999, 2);
function change_select_options_button_text($label, $product) {
if (is_product_category('cat1') && $product->is_type('variable')) {
return '选择日期';
}
return $label;
}
任何帮助将不胜感激。
谢谢!
英文:
I have the following code that changes the button text of a variable product from 'select options' to select dates.
add_filter( 'woocommerce_product_add_to_cart_text', 'change_select_options_button_text', 9999, 2 );
function change_select_options_button_text( $label, $product ) {
if ( $product->is_type( 'variable' ) ) {
return 'Select Dates';
}
return $label;
}
I'm wanting to apply this only to a certain category instead of it applying to every variable product. Would this be possible?
I've tried adding : if ( is_product_category('cat1')
like so but have had no luck.
add_filter( 'woocommerce_product_add_to_cart_text', 'change_select_options_button_text', 9999, 2 );
function change_select_options_button_text( $label, $product ) {
if ( is_product_category('cat1') && $product->is_type( 'variable' ) ) {
return 'Select Dates';
}
return $label;
}
Any help would be greatly appreciated.
Thank You!
答案1
得分: 1
add_filter('woocommerce_product_add_to_cart_text', 'change_select_options_button_text', 9999, 2);
function change_select_options_button_text($label, $product) {
if ($product->is_type('variable') && has_term(array('kids clothing'), 'product_cat', $product->get_id())) {
// 如果产品是可变的,并且属于“kids clothing”类别,则执行某些操作
return '选择日期';
}
return $label;
}
英文:
add_filter('woocommerce_product_add_to_cart_text', 'change_select_options_button_text', 9999, 2);
function change_select_options_button_text($label, $product) {
if ($product->is_type('variable') && has_term(array('kids clothing'), 'product_cat', $product->get_id())) {
// Do something if the product is variable and in category "kids clothing"
return 'Select Dates';
}
return $label;
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论