例如,这是一个自定义添加到购物车按钮,我在将放置位置的产品管理页面中添加了自定义或自定义添加的字段代码。并且在客户端或用户端,如果用户不能使用“添加到购物车”按钮,则该按钮不能对应产品详细信息中保存的相同确切位置。
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);