php - Woocommerce/Wordpress(Avada Theme) Remove Add to Cart and Details Buttons on Category Pages
I want to remove the Add to Cart Button and the Details button from the Product Category Pages, but more specifically only for specific products that have a specific custom meta data.
I've set up a custom plugin to add an admin box that has a simple checkbox on product admin pages that asks if the product is "Coming Soon" if the checkbox is checked it sets the custom meta data value for "comingsoon-checkbox" to "Yes". If it is unchecked it will be "No".
The issue is with using the Avada plugin, it adds and replaces some of the actions for woocommerce. So I've been able to replace add to cart button on the actual product page, but on the category page I can't figure out how to do it.
function remove_woo_commerce_hooks() {
global $avada_woocommerce;
$coming_soon = get_post_meta( get_the_ID(), 'comingsoon-checkbox', true );
if ($coming_soon == 'yes'){
remove_action( 'woocommerce_after_shop_loop_item', array( $avada_woocommerce, 'template_loop_add_to_cart' ), 10 );
remove_action( 'woocommerce_after_shop_loop_item', array( $avada_woocommerce, 'show_details_button' ), 15 );
add_action( 'woocommerce_after_shop_loop_item', 'coming_soon_text', 30 );
}
}
add_action( 'after_setup_theme', 'remove_woo_commerce_hooks' );
Also on category pages the meta data returns null. Is there a way to achieve this?
Thanks.
Answer
Solution:
I've figured out my own question for those looking for this. I changed the "add_action" as it wasn't running at the correct time to remove the buttons.
add_action( 'woocommerce_shop_loop_item_title', 'remove_woo_commerce_hooks');
function remove_woo_commerce_hooks() {
global $avada_woocommerce;
$coming_soon = get_post_meta( get_the_ID(), 'comingsoon-checkbox', true );
if ($coming_soon == 'yes'){
remove_action( 'woocommerce_after_shop_loop_item', array( $avada_woocommerce, 'template_loop_add_to_cart' ), 10 );
remove_action( 'woocommerce_after_shop_loop_item', array( $avada_woocommerce, 'show_details_button' ), 15 );
add_action( 'woocommerce_after_shop_loop_item', 'coming_soon_text', 30 );
}
else{
add_action( 'woocommerce_after_shop_loop_item', array( $avada_woocommerce, 'template_loop_add_to_cart' ), 10 );
add_action( 'woocommerce_after_shop_loop_item', array( $avada_woocommerce, 'show_details_button' ), 15 );
}
}
And this is the coming_soon_text function.
function coming_soon_text(){
$coming_soon = get_post_meta( get_the_ID(), 'comingsoon-checkbox', true );
if ($coming_soon == 'yes'){
echo '<div class="comingsoontext">PRODUCT COMING SOON</div>';
}
}
Source