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/
5. Action Hooks - Example 1: Event
add_action( 'save_post_product', 'trigger' );
function trigger() {
// do something when save product
}
CustomizeWoo.com
6. Action Hooks - Example 2: Position
do_action( 'woocommerce_before_cart' );
CustomizeWoo.com
7. Action Hooks - Example 2: Position
add_action( 'woocommerce_before_cart',
'cart_banner' );
function cart_banner() {
// do something before Cart table
}
CustomizeWoo.com
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. 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. 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
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. Action Hooks: WC Example
do_action( 'woocommerce_before_cart' );
add_action( 'woocommerce_before_cart', 'echo_test' );
function echo_test() {
echo 'TEST';
}
CustomizeWoo.com
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. 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