0
votes

Everything I can find on removing the WooComm Add To Cart button will remove not just the add to cart button but also the pricing/variations, aka the whole add to cart area.

My goal is to enable/disable the ability to purchase a product with a checkbox/selector on the product info page. BUT I still have to be able to see the product variation pricing and the variation drop down menu.

This is important. The pricing shown under the product title, for a variation, will be something like $20.00 - $40.00 and not until you select the variation choice will it show the price next to the add to cart button.

So far I have things working wherein I can remove the add to cart area — variations and all — conditionally on my custom field, but I have no idea how to hide/disable click/remove just the add to cart button and allow variations to still be chosen with the variation price displayed.

function remove_add_to_cart(){
    if(get_post_meta(get_the_ID(), 'woo_callforinfo', true)) {
        remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
    }
} add_action('woocommerce_single_product_summary','remove_add_to_cart');
3

3 Answers

0
votes

Here's what I did. The conditional IF statement is because I have a RETAIL shop with variable products that I don't want affected.

function remove_add_to_cart(){
if ( has_term( 'wholesale', 'product_tag' ) ) {

    remove_action( 'woocommerce_single_variation', 'woocommerce_single_variation_add_to_cart_button', 20 );

}
} 

add_action('woocommerce_single_variation','remove_add_to_cart');
0
votes

Added this to get rid of the 'Sorry..' message if price is not set.

 add_filter( 'gettext', 'customizing_product_variation_message', 10, 3 );
 function customizing_product_variation_message( $translated_text, 
 $untranslated_text, $domain )
 {
     if ($untranslated_text == 'Sorry, this product is unavailable. Please choose a different combination.') {
    $translated_text = __( '-type anything you want here, or leave a space- ', $domain );
}
return $translated_text;
}
0
votes

Just add the following code in your functions.php and you will find button hidden

I don't know whether my solution is perfect. But it works. Normally if is_purchasable is returned to the filter woocommerce_is_purchasable, the ‘Add to Cart’ button is displayed, and if false is returned the button is hidden. So, you just need to add the following:

add_filter('woocommerce_is_purchasable', 'my_woocommerce_is_purchasable', 10, 2);

function my_woocommerce_is_purchasable($is_purchasable, $product) {
 // Write code to access custom field value in this function
 // let $custom_value be the value from checkbox
  return ($custom_value == false ? false : $is_purchasable);
}

No incompatibility issues would creep up.