jam*_*ggs 2 wordpress woocommerce
我需要将“添加到购物车”按钮(仅在某些类别上)替换为“给经销商发短信”的自定义按钮。“给经销商发短信”按钮将触发灯箱中的重力表单,允许用户通过 Twilio SMS 服务提交短信。
这是一个屏幕截图
我想我知道如何将按钮链接到灯箱中的表单,但我不知道如何替换按钮。
add_filter( 'woocommerce_loop_add_to_cart_link', 'replace_default_button' );
function replace_default_button(){
return '<button>Text a Dealer</button>';
}
Run Code Online (Sandbox Code Playgroud)
您可以将按钮代码替换为您想要的代码。这会将默认按钮代码替换为您的自定义代码。
您还希望此自定义仅适用于某些类别。这可以通过添加更多代码来实现。见下文。
add_filter( 'woocommerce_loop_add_to_cart_link', 'replace_default_button' );
function replace_default_button(){
//list category slugs where button needs to be changed
$selected_cats = array('cat-one-slug', 'cat-two-slug', 'cat-three-slug');
//get current category object
$current_cat = get_queried_object();
//get category slug from category object
$current_cat_slug = $current_cat->slug;
//check if current category slug is in the selected category list
if( in_array($current_cat_slug, $selected_cats) ){
//replace default button code with custom code
return '<button>Text a Dealer</button>';
}
}
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助。
| 归档时间: |
|
| 查看次数: |
14094 次 |
| 最近记录: |