This is a customize add to cart button for example I added a custom or custom added field code in a product admin page that will place a location. and in the client or user side, the user cannot use the add to cart button if it cannot correspond the same exact location saved in the product details.
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';
}
}
2
Answers
Hope this help you.
Add the following code snippet in the Theme Functions (function.php) file of your currently activated theme as required.
Change Button Text
Remove Add to cart buttons