I wanted to add the action hook below only if we are not in a specific product ID. So i tried something like this in my functions.php
global $product;
$productId = $product->get_id();
if ($productId != 1345){
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 10 );
}
But, it's impossible to call the $product variable out of a function.
So i tried to do this
function woocommerce_add_new_add_to_cart(){
global $product;
$productId = $product->get_id();
if ($productId != 1345){
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 10 );
}
}
add_action('woocommerce_single_product_summary', 'woocommerce_add_new_add_to_cart', 10);
And it didn't work as well.
So then i found this post : Is it possible to create an action hook using do_action() within add_action()?
And i tried this
function woocommerce_add_new_add_to_cart(){
global $product;
$productId = $product->get_id();
if ($productId != 1345){
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 10 );
}
}
add_action('woocommerce_single_product_summary', function(){do_action('woocommerce_add_new_add_to_cart');});
And it doesn't work as well. What's wrong ? How can i do this ? Any idea ? :/
Thanks