Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

WooCommerce: Issues With remove action()

10 views

Published on

These slides belong to https://CustomizeWoo.com, a technical video course that shows you how to override WooCommerce pages and elements without using plugins. You can watch me code and learn by example.

A series of videos, screencasts, examples and exercises will help you feel more confident about WooCommerce customization, child themes, hooks and CSS/PHP snippets.

Watch and re-watch each video how many times you like, get lifetime access to me via the comment section, exercise as much as possible and keep learning.

Access your free videos or buy the course via https://businessbloomer.com/customizewoo-master-woocommerce-online-course/

Published in: Internet
  • Be the first to comment

  • Be the first to like this

WooCommerce: Issues With remove action()

  1. 1. Remove_Action Issues CustomizeWoo.com
  2. 2. "remove_action" add_action triggers a function attached to a specific hook remove_action removes that same function CustomizeWoo.com
  3. 3. Issues with remove_action CustomizeWoo.com 1. Wrong syntax 2. Removing something before it's added with add_action (doesn't exist yet) 3. Theme/plugin already removing add_action and re-adding it elsewhere 4. add_action contains "$this"
  4. 4. Correct (Matching) Syntax add_action( 'hook_name', 'func_name', 99, 5 ); remove_action( 'hook_name', 'func_name', 99, 5 ); CustomizeWoo.com
  5. 5. Removing Later add_action( 'wp', 'delay' ); function delay( ) { remove_action( 'hook_name', 'func_name', 99, 5 ); } CustomizeWoo.com
  6. 6. Removing Correct add_action THEME: remove_action( 'hook_name', 'func_name' ); // WC Default! add_action( 'diff_hook_name', 'func_name' ); // Custom! YOU: add_action( 'wp', 'delay' ); function delay( ) { remove_action( 'diff_hook_name', 'func_name' ); } CustomizeWoo.com
  7. 7. add_action with $this CustomizeWoo.com ● Added by a class (plugin, theme) e.g. add_action( 'hook', array( $this, 'func' ) ); ● You can't just do: remove_action( 'hook', array( $this, 'func' ) ); as $this is not defined ● $this is the PHP class instance so: ○ need to remove_action AFTER add_action ○ need to dig deep into the PHP class and find out more about it e.g. if global exists
  8. 8. remove_action with $this = $global CustomizeWoo.com add_action( 'wp', 'delay' ); function delay( ) { global $my_class; remove_action( 'hook_name', array ( $my_class, 'func_name' ) ); }
  9. 9. remove_action with static function CustomizeWoo.com add_action( 'wp', 'delay' ); function delay( ) { remove_action( 'hook_name', array ( 'class_name', 'func_name' ) ); }
  10. 10. remove_action with class instance CustomizeWoo.com add_action( 'wp', 'delay' ); function delay( ) { remove_action( 'hook_name', array ( Class_Name(), 'func_name' ) ); }

×