Plugin custom Action Hook not working

Your plugin needs to wait for the themes functions.php file to be loaded. Try this: <?php /* Plugin Name: Demo Plugin Version: 1.0 */ add_action( ‘after_setup_theme’, function() { do_action( ‘basic_action_demo’ ); } ); ?> The after_setup_theme hook is run immediately after functions.php is loaded. Update for your comment below. In your plugin create a function … Read more

add_filter to ‘woocommerce_before_main_content’ [closed]

woocommerce_before_main_content is not a filter hook, it’s an action hook, so don’t expect it to return something, because nothing cares about what an action hook callback function returns, whereas for filters hooks, you will always see something waiting for the returned result: // Action hook do_action(‘foo_action’); // Filter hook $bar = apply_filters(‘foo_filter’); woocommerce_before_main_content That action … Read more

How to unhook a function in Woocommerce Template?

You need to unhook the function from that action specifically: remove_action( ‘woocommerce_review_before_comment_meta’, ‘woocommerce_review_display_rating’, 10 ); (e.g. look for the opposite add_action() line in includes/wc-template-hooks.php) You’ll also need to make sure that this is run after WooCommerce has loaded and added the action you’re about to remove, e.g. place this in a plugins_loaded hook: function unhook_display_rating() … Read more

Can I use a method from an existing plugin as an action hook?

It sounds like you are looking for do_action() In your method that you wrote add do_action and it will trigger your new custom action. Then you can use add_action() in the same way you use the build in actions. https://developer.wordpress.org/reference/functions/do_action/ Example of your method in the class… public function some_method() { $foo = ‘puppy’; $bar=”bunny”; … Read more