If you are looking to remove the Add to Cart button in WooCommerce and replace it with a custom button then this short snippet is for you.

/** * Disables Add to cart button and replaced it with Read more. **/ add_filter( 'woocommerce_is_purchasable', false ); /** * Disable all except specific products */ add_filter('woocommerce_is_purchasable', 'wpharvest_is_purchasable', 10, 2); function wpharvest_is_purchasable( $is_purchasable, $object ) { // Checks to see if the product id is 22 or 23, // returns true if is, false otherwise. return ( 22 === $object->id || 23 === $object->id ); }
Code language: PHP (php)

Did you find this snippet useful? If so, or if you encountered any issues with it, please let us know in the comments section below.

Published by Dragos Micu


Leave a Reply

Your email address will not be published. Required fields are marked *