我是wordpress hooks的新手。如何自定义启用和禁用“添加到购物车”按钮
这是一个自定义添加到购物车按钮,例如,我在产品管理页面中添加了一个自定义或自定义添加的字段代码,用于放置一个位置。在客户端或用户端,如果“添加到购物车”按钮不能对应于“产品详细信息”中保存的相同确切位置,则用户不能使用该按钮我是wordpress hooks的新手。如何自定义启用和禁用“添加到购物车”按钮,wordpress,woocommerce,customization,Wordpress,Woocommerce,Customization,这是一个自定义添加到购物车按钮,例如,我在产品管理页面中添加了一个自定义或自定义添加的字段代码,用于放置一个位置。在客户端或用户端,如果“添加到购物车”按钮不能对应于“产品详细信息”中保存的相同确切位置,则用户不能使用该按钮 add_action('template_redirect', function (){ global $post; if(isset($_POST['loc-address']) && ! empty($_POST['loc-address
add_action('template_redirect', function (){
global $post;
if(isset($_POST['loc-address']) && ! empty($_POST['loc-address'])){
//setcookie
setcookie("loc_address", $_POST['loc-address'], time() + 3600);
//check if this was a product post type
if(!is_null($_POST['loc-address']) && !empty($_COOKIE['loc_address'])){
$value_product = wc_get_product($post->ID);
remove_action('woocommerce_variable_add_to_cart', 'woocommerce_variable_add_to_cart', 30);
}
else {
echo 'Enable add to cart button';
}
}
希望这对你有帮助
add_filter( 'woocommerce_is_purchasable', 'vna_is_purchasable', function , 10, 2 );
vna_is_purchasable( $purchasable, $product ){
return true || false; // depending on your condition
}
根据需要,在当前激活主题的主题函数(function.php)文件中添加以下代码段 更改按钮文本
add_filter('woocommerce_product_single_add_to_cart_text','custom_add_to_cart_button_woocommerce');
function custom_add_to_cart_button_woocommerce() {
return __('WooCommerce custom add to cart button code', 'woocommerce');
}
删除“添加到购物车”按钮
remove_action('woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart');
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 20);