Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save themepaint/80fdf7fed0618eb2be01 to your computer and use it in GitHub Desktop.
Save themepaint/80fdf7fed0618eb2be01 to your computer and use it in GitHub Desktop.
Remove WooCommerce purchase button on a category
function themepaint_custome_add_to_cart(){
if ( ! is_product() ) return;
$product = get_product();
if ( has_term('posters','product_cat',$product ) || themepaint_is_child_of_turm( 'posters','product_cat',$product )) {
/**
* Product Add to cart.
*
* @see woocommerce_template_single_add_to_cart()
* @see woocommerce_simple_add_to_cart()
* @see woocommerce_grouped_add_to_cart()
* @see woocommerce_variable_add_to_cart()
* @see woocommerce_external_add_to_cart()
* @see woocommerce_single_variation()
* @see woocommerce_single_variation_add_to_cart_button()
*/
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
remove_action( 'woocommerce_simple_add_to_cart', 'woocommerce_simple_add_to_cart', 30 );
remove_action( 'woocommerce_grouped_add_to_cart', 'woocommerce_grouped_add_to_cart', 30 );
remove_action( 'woocommerce_variable_add_to_cart', 'woocommerce_variable_add_to_cart', 30 );
remove_action( 'woocommerce_external_add_to_cart', 'woocommerce_external_add_to_cart', 30 );
add_action( 'woocommerce_single_product_summary', 'cart_custome_text', 30 );
add_action( 'woocommerce_simple_add_to_cart', 'cart_custome_text', 30 );
add_action( 'woocommerce_grouped_add_to_cart', 'cart_custome_text', 30 );
add_action( 'woocommerce_variable_add_to_cart', 'cart_custome_text', 30 );
add_action( 'woocommerce_external_add_to_cart', 'cart_custome_text', 30 );
}
}
add_action('wp','themepaint_custome_add_to_cart');
function themepaint_is_child_of_turm( $term, $taxonomy, $post_object ){
$term = get_term_by( 'slug', $term, $taxonomy );
$post_terms = get_the_terms( (int) $post_object->ID, (string) $taxonomy );
$post_term_parent_ids = wp_list_pluck( $post_terms, 'parent' );
if ( in_array( $term->term_id, $post_term_parent_ids )) {
return true;
}
return false;
}
function cart_custome_text(){
echo '<p>Please Contact Raju</p>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment