as the title states, I’m trying to remove the buy button for virtual products. I am using the Astra theme in WordPress alongside Woocommerce, and Elementor.
Now my issue is that with my current implementation, it does remove the button from the individual product page. However it still displays the button on the categories page, which is a pain. I have tried setting the price to nothing, and while that does work. It doesn’t help as I still want the products to have their prices listed.
I have added the following code to the functions.php section of my duplicated theme file;
function buy_filter()
{
if ( ! is_product() ) return;
$product = get_product();
if ($product->is_virtual('yes'))
{
//$product->is_purchasable('false')
//remove_action( 'woocommerce_before_shop_loop', 'woocommerce_result_count', 20 );
//remove_action('woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 30);
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart' );
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 ('wp', 'buy_filter');
Any help would be greatly appreciated, and I’m happy to give any more details I can to aid in the matter.
Thank you kindly!
2
Answers
You need to get the specific product by it’s ID, I have modified a few part of your code and removed few of the hooks you used. Please add those if required.
Hope it works.
This is the hook you are looking for