Here is my code
add_action( 'init', 'my_function' );
function my_function() {
global $post;
if (get_field('show_form', $post->ID)) {
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
}
}
Using a true/false field within Woocommerce product pages
Screenshot: https://madshot.net/9e9107cd443b.png
If they option is check I’m trying to run certain action to hide certain elements. I can’t get it to work. I’ve tried other things than what I’ve posted but everything I’ve read shows that this should work. Thoughts?
The global $post value will not be valid on the init
hook. You can’t use this until after this global is set up inside of the loop. The earliest hook you may be able to use would probably bewp
https://codex.wordpress.org/Plugin_API/Action_Reference. You may also need to use https://codex.wordpress.org/Function_Reference/get_queried_object to get the post and ID since I’m pretty sure that $post still won’t have a value outside of “The Loop”