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: Action Hooks

2 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: Action Hooks

  1. 1. Getting Ready: Action Hooks CustomizeWoo.com
  2. 2. WordPress Action Hooks 1/2 Allow you to run / "hook" a PHP function at specific execution times or in a specific template position CustomizeWoo.com
  3. 3. WordPress Action Hooks 2/2 tl;dr: if WP/WC provide do_action( 'hook_name' ) you can run a custom function there/then CustomizeWoo.com
  4. 4. Action Hooks - Example 1: Event do_action( 'save_post_product' ); CustomizeWoo.com
  5. 5. Action Hooks - Example 1: Event add_action( 'save_post_product', 'trigger' ); function trigger() { // do something when save product } CustomizeWoo.com
  6. 6. Action Hooks - Example 2: Position do_action( 'woocommerce_before_cart' ); CustomizeWoo.com
  7. 7. Action Hooks - Example 2: Position add_action( 'woocommerce_before_cart', 'cart_banner' ); function cart_banner() { // do something before Cart table } CustomizeWoo.com
  8. 8. Action Hooks: do_action Syntax do_action( 'hook_name', $args ); ● kindly provided by WP/themes/plugins ● e.g. do_action( 'woocommerce_thankyou', $order->get_id() ); ● $args = variables you can "pass" and use in your hooked function CustomizeWoo.com
  9. 9. Action Hooks: add_action Syntax add_action( 'hook_name', 'func_name', 10, 1 ); ● goes in functions.php @ child theme ● same "hook_name" as per do_action ● hooked function ● priority = 10 by default / if omitted ● args = 1 by default / if omitted CustomizeWoo.com
  10. 10. Action Hooks: function Syntax function func_name( $args ) { } ● goes in functions.php @ child theme ● hooked function (name as per add_action) ● $args = as per do_action CustomizeWoo.com
  11. 11. Action Hooks: tl;dr Syntax do_action( 'hook_name', $arg1, $arg2, ... ); add_action( 'hook_name', 'func_name', 10, 2 ); function func_name( $arg1, $arg2, ... ) { } CustomizeWoo.com
  12. 12. Action Hooks: WC Example do_action( 'woocommerce_before_cart' ); add_action( 'woocommerce_before_cart', 'echo_test' ); function echo_test() { echo 'TEST'; } CustomizeWoo.com
  13. 13. Action Hooks: WC Example do_action( 'woocommerce_before_cart' ); add_action( 'woocommerce_before_cart', 'echo_test' ); function echo_test() { echo 'TEST'; } CustomizeWoo.com
  14. 14. Action Hooks: Project Checklist 1. Project Specs e.g. "Add banner above Cart" 2. Search for do_action() or use the "WooCommerce Cart Visual Hook Guide" 3. Pick a hook e.g. "woocommerce_before_cart" 4. Hook your function with add_action() 5. Write your trigger function CustomizeWoo.com
  15. 15. Action Hooks: Recap ● Help us override WooCommerce etc. without editing core / template files (add_action() and function go in functions.php @ child theme) ● Easy to find: file search for "do_action" or use Visual Hook Guides CustomizeWoo.com

×