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.
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>';
}
}
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.
PHP (from the English Hypertext Preprocessor - hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites.
The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.
https://www.php.net/
Welcome to the Q&A site for web developers. Here you can ask a question about the problem you are facing and get answers from other experts. We have created a user-friendly interface so that you can quickly and free of charge ask a question about a web programming problem. We also invite other experts to join our community and help other members who ask questions. In addition, you can use our search for questions with a solution.
Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.
Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.