SlideShare une entreprise Scribd logo
1  sur  15
Télécharger pour lire hors ligne
Getting Ready:
Action Hooks
CustomizeWoo.com
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
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
Action Hooks - Example 1: Event
do_action( 'save_post_product' );
CustomizeWoo.com
Action Hooks - Example 1: Event
add_action( 'save_post_product', 'trigger' );
function trigger() {
// do something when save product
}
CustomizeWoo.com
Action Hooks - Example 2: Position
do_action( 'woocommerce_before_cart' );
CustomizeWoo.com
Action Hooks - Example 2: Position
add_action( 'woocommerce_before_cart',
'cart_banner' );
function cart_banner() {
// do something before Cart table
}
CustomizeWoo.com
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
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
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
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
Action Hooks: WC Example
do_action( 'woocommerce_before_cart' );
add_action( 'woocommerce_before_cart', 'echo_test' );
function echo_test() {
echo 'TEST';
}
CustomizeWoo.com
Action Hooks: WC Example
do_action( 'woocommerce_before_cart' );
add_action( 'woocommerce_before_cart', 'echo_test' );
function echo_test() {
echo 'TEST';
}
CustomizeWoo.com
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
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

Contenu connexe

Tendances

Perl web frameworks
Perl web frameworksPerl web frameworks
Perl web frameworks
diego_k
 
優しいWAFの作り方
優しいWAFの作り方優しいWAFの作り方
優しいWAFの作り方
techmemo
 

Tendances (20)

The Promised Land (in Angular)
The Promised Land (in Angular)The Promised Land (in Angular)
The Promised Land (in Angular)
 
Promises, promises, and then observables
Promises, promises, and then observablesPromises, promises, and then observables
Promises, promises, and then observables
 
Asynchronous Programming FTW! 2 (with AnyEvent)
Asynchronous Programming FTW! 2 (with AnyEvent)Asynchronous Programming FTW! 2 (with AnyEvent)
Asynchronous Programming FTW! 2 (with AnyEvent)
 
Avoiding callback hell in Node js using promises
Avoiding callback hell in Node js using promisesAvoiding callback hell in Node js using promises
Avoiding callback hell in Node js using promises
 
Webrtc mojo
Webrtc mojoWebrtc mojo
Webrtc mojo
 
Perl web frameworks
Perl web frameworksPerl web frameworks
Perl web frameworks
 
Anyevent
AnyeventAnyevent
Anyevent
 
The Beauty of Java Script
The Beauty of Java ScriptThe Beauty of Java Script
The Beauty of Java Script
 
Javascript - Beyond-jQuery
Javascript - Beyond-jQueryJavascript - Beyond-jQuery
Javascript - Beyond-jQuery
 
Perl: Coro asynchronous
Perl: Coro asynchronous Perl: Coro asynchronous
Perl: Coro asynchronous
 
優しいWAFの作り方
優しいWAFの作り方優しいWAFの作り方
優しいWAFの作り方
 
Mojo as a_client
Mojo as a_clientMojo as a_client
Mojo as a_client
 
Callbacks, promises, generators - asynchronous javascript
Callbacks, promises, generators - asynchronous javascriptCallbacks, promises, generators - asynchronous javascript
Callbacks, promises, generators - asynchronous javascript
 
How to develop modern web application framework
How to develop modern web application frameworkHow to develop modern web application framework
How to develop modern web application framework
 
Asynchronous programming done right - Node.js
Asynchronous programming done right - Node.jsAsynchronous programming done right - Node.js
Asynchronous programming done right - Node.js
 
How to Vim - for beginners
How to Vim - for beginnersHow to Vim - for beginners
How to Vim - for beginners
 
Understanding Asynchronous JavaScript
Understanding Asynchronous JavaScriptUnderstanding Asynchronous JavaScript
Understanding Asynchronous JavaScript
 
Web Apps in Perl - HTTP 101
Web Apps in Perl - HTTP 101Web Apps in Perl - HTTP 101
Web Apps in Perl - HTTP 101
 
Promises, Promises
Promises, PromisesPromises, Promises
Promises, Promises
 
JavaScript Promises
JavaScript PromisesJavaScript Promises
JavaScript Promises
 

Similaire à WooCommerce: Action Hooks

How Not to Build a WordPress Plugin
How Not to Build a WordPress PluginHow Not to Build a WordPress Plugin
How Not to Build a WordPress Plugin
Will Norris
 
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
arcware
 
Laying the proper foundation for plugin and theme development
Laying the proper foundation for plugin and theme developmentLaying the proper foundation for plugin and theme development
Laying the proper foundation for plugin and theme development
Tammy Hart
 
Javascript Frameworks for Joomla
Javascript Frameworks for JoomlaJavascript Frameworks for Joomla
Javascript Frameworks for Joomla
Luke Summerfield
 

Similaire à WooCommerce: Action Hooks (20)

Hooks WCSD12
Hooks WCSD12Hooks WCSD12
Hooks WCSD12
 
How Not to Build a WordPress Plugin
How Not to Build a WordPress PluginHow Not to Build a WordPress Plugin
How Not to Build a WordPress Plugin
 
Ten useful JavaScript tips & best practices
Ten useful JavaScript tips & best practicesTen useful JavaScript tips & best practices
Ten useful JavaScript tips & best practices
 
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
 
Hooking with WordPress by Rahul Prajapati - COEP FOSSMeet March 2019
Hooking with WordPress by Rahul Prajapati - COEP FOSSMeet March 2019Hooking with WordPress by Rahul Prajapati - COEP FOSSMeet March 2019
Hooking with WordPress by Rahul Prajapati - COEP FOSSMeet March 2019
 
WooCommerce: Filter Hooks
WooCommerce: Filter HooksWooCommerce: Filter Hooks
WooCommerce: Filter Hooks
 
Building Robust jQuery Plugins
Building Robust jQuery PluginsBuilding Robust jQuery Plugins
Building Robust jQuery Plugins
 
Writing Maintainable JavaScript
Writing Maintainable JavaScriptWriting Maintainable JavaScript
Writing Maintainable JavaScript
 
Demystifying Hooks, Actions & Filters - WordCamp Belfast 2018
Demystifying Hooks, Actions & Filters - WordCamp Belfast 2018Demystifying Hooks, Actions & Filters - WordCamp Belfast 2018
Demystifying Hooks, Actions & Filters - WordCamp Belfast 2018
 
Laying the proper foundation for plugin and theme development
Laying the proper foundation for plugin and theme developmentLaying the proper foundation for plugin and theme development
Laying the proper foundation for plugin and theme development
 
Javascript Frameworks for Joomla
Javascript Frameworks for JoomlaJavascript Frameworks for Joomla
Javascript Frameworks for Joomla
 
Actions filters
Actions filtersActions filters
Actions filters
 
Service worker: discover the next web game changer
Service worker: discover the next web game changerService worker: discover the next web game changer
Service worker: discover the next web game changer
 
WooCommerce actions
WooCommerce actionsWooCommerce actions
WooCommerce actions
 
Как получить чёрный пояс по WordPress? v2.0
Как получить чёрный пояс по WordPress? v2.0Как получить чёрный пояс по WordPress? v2.0
Как получить чёрный пояс по WordPress? v2.0
 
jQuery: Events, Animation, Ajax
jQuery: Events, Animation, AjaxjQuery: Events, Animation, Ajax
jQuery: Events, Animation, Ajax
 
Как получить чёрный пояс по WordPress?
Как получить чёрный пояс по WordPress?Как получить чёрный пояс по WordPress?
Как получить чёрный пояс по WordPress?
 
Using Actions and Filters in WordPress to Make a Plugin Your Own
Using Actions and Filters in WordPress to Make a Plugin Your OwnUsing Actions and Filters in WordPress to Make a Plugin Your Own
Using Actions and Filters in WordPress to Make a Plugin Your Own
 
Virtual Madness @ Etsy
Virtual Madness @ EtsyVirtual Madness @ Etsy
Virtual Madness @ Etsy
 
jQuery secrets
jQuery secretsjQuery secrets
jQuery secrets
 

Plus de Rodolfo Melogli

Plus de Rodolfo Melogli (20)

WordCamp Italia 2021: da zero a PHP
WordCamp Italia 2021: da zero a PHPWordCamp Italia 2021: da zero a PHP
WordCamp Italia 2021: da zero a PHP
 
WooCommerce: Issues With remove action()
WooCommerce: Issues With remove action()WooCommerce: Issues With remove action()
WooCommerce: Issues With remove action()
 
WooCommerce: Custom Fields
WooCommerce: Custom FieldsWooCommerce: Custom Fields
WooCommerce: Custom Fields
 
WooCommerce: Conditional Logic
WooCommerce: Conditional LogicWooCommerce: Conditional Logic
WooCommerce: Conditional Logic
 
WooCommerce: Intro to PHP
WooCommerce: Intro to PHPWooCommerce: Intro to PHP
WooCommerce: Intro to PHP
 
WooCommerce: Intro to CSS
WooCommerce: Intro to CSSWooCommerce: Intro to CSS
WooCommerce: Intro to CSS
 
WooCommerce: Shortcodes
WooCommerce: ShortcodesWooCommerce: Shortcodes
WooCommerce: Shortcodes
 
WooCommerce: Anatomy of a Template File
WooCommerce: Anatomy of a Template FileWooCommerce: Anatomy of a Template File
WooCommerce: Anatomy of a Template File
 
WooCommerce: Where to Place Customization
WooCommerce: Where to Place CustomizationWooCommerce: Where to Place Customization
WooCommerce: Where to Place Customization
 
WooCommerce: Plugin Settings Overview
WooCommerce: Plugin Settings OverviewWooCommerce: Plugin Settings Overview
WooCommerce: Plugin Settings Overview
 
WooCommerce: Customization Mistakes to Avoid
WooCommerce: Customization Mistakes to AvoidWooCommerce: Customization Mistakes to Avoid
WooCommerce: Customization Mistakes to Avoid
 
WooCommerce: Customization Definitions
WooCommerce: Customization DefinitionsWooCommerce: Customization Definitions
WooCommerce: Customization Definitions
 
WooCommerce: Customization FAQ
WooCommerce: Customization FAQWooCommerce: Customization FAQ
WooCommerce: Customization FAQ
 
10 PHP Snippets to Increase WooCommerce Sales
10 PHP Snippets to Increase WooCommerce Sales10 PHP Snippets to Increase WooCommerce Sales
10 PHP Snippets to Increase WooCommerce Sales
 
WooCommerce Workshop. INSTALL. SET UP. PUBLISH. SELL.
WooCommerce Workshop. INSTALL. SET UP. PUBLISH. SELL.WooCommerce Workshop. INSTALL. SET UP. PUBLISH. SELL.
WooCommerce Workshop. INSTALL. SET UP. PUBLISH. SELL.
 
How to Sell ANYTHING with WordPress + WooCommerce
How to Sell ANYTHING with WordPress + WooCommerceHow to Sell ANYTHING with WordPress + WooCommerce
How to Sell ANYTHING with WordPress + WooCommerce
 
WooCommerce Customization Masterclass (WordCamp Dublin 2017)
WooCommerce Customization Masterclass (WordCamp Dublin 2017)WooCommerce Customization Masterclass (WordCamp Dublin 2017)
WooCommerce Customization Masterclass (WordCamp Dublin 2017)
 
5 Growth Hacking Strategies + Google Analytics tips & tricks
5 Growth Hacking Strategies + Google Analytics tips & tricks5 Growth Hacking Strategies + Google Analytics tips & tricks
5 Growth Hacking Strategies + Google Analytics tips & tricks
 
From Purchase to Customer Satisfaction: 7 Ways to Increase your Sales
From Purchase to Customer Satisfaction: 7 Ways to Increase your SalesFrom Purchase to Customer Satisfaction: 7 Ways to Increase your Sales
From Purchase to Customer Satisfaction: 7 Ways to Increase your Sales
 
Top 15 Sales Generation Techniques (Ecommerce Customer Acquisition)
Top 15 Sales Generation Techniques (Ecommerce Customer Acquisition)Top 15 Sales Generation Techniques (Ecommerce Customer Acquisition)
Top 15 Sales Generation Techniques (Ecommerce Customer Acquisition)
 

Dernier

一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
ayvbos
 
PowerDirector Explination Process...pptx
PowerDirector Explination Process...pptxPowerDirector Explination Process...pptx
PowerDirector Explination Process...pptx
galaxypingy
 
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girlsRussian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
Monica Sydney
 
75539-Cyber Security Challenges PPT.pptx
75539-Cyber Security Challenges PPT.pptx75539-Cyber Security Challenges PPT.pptx
75539-Cyber Security Challenges PPT.pptx
Asmae Rabhi
 
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
ydyuyu
 
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
pxcywzqs
 
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
gajnagarg
 
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
ydyuyu
 
Indian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Indian Escort in Abu DHabi 0508644382 Abu Dhabi EscortsIndian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Indian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Monica Sydney
 

Dernier (20)

Real Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirtReal Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirt
 
20240508 QFM014 Elixir Reading List April 2024.pdf
20240508 QFM014 Elixir Reading List April 2024.pdf20240508 QFM014 Elixir Reading List April 2024.pdf
20240508 QFM014 Elixir Reading List April 2024.pdf
 
Power point inglese - educazione civica di Nuria Iuzzolino
Power point inglese - educazione civica di Nuria IuzzolinoPower point inglese - educazione civica di Nuria Iuzzolino
Power point inglese - educazione civica di Nuria Iuzzolino
 
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
 
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoil
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime NagercoilNagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoil
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoil
 
PowerDirector Explination Process...pptx
PowerDirector Explination Process...pptxPowerDirector Explination Process...pptx
PowerDirector Explination Process...pptx
 
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girlsRussian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
 
Trump Diapers Over Dems t shirts Sweatshirt
Trump Diapers Over Dems t shirts SweatshirtTrump Diapers Over Dems t shirts Sweatshirt
Trump Diapers Over Dems t shirts Sweatshirt
 
75539-Cyber Security Challenges PPT.pptx
75539-Cyber Security Challenges PPT.pptx75539-Cyber Security Challenges PPT.pptx
75539-Cyber Security Challenges PPT.pptx
 
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
 
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
 
Meaning of On page SEO & its process in detail.
Meaning of On page SEO & its process in detail.Meaning of On page SEO & its process in detail.
Meaning of On page SEO & its process in detail.
 
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
 
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
 
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrStory Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
 
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
 
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Room
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac RoomVip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Room
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Room
 
Microsoft Azure Arc Customer Deck Microsoft
Microsoft Azure Arc Customer Deck MicrosoftMicrosoft Azure Arc Customer Deck Microsoft
Microsoft Azure Arc Customer Deck Microsoft
 
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...
 
Indian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Indian Escort in Abu DHabi 0508644382 Abu Dhabi EscortsIndian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Indian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
 

WooCommerce: Action Hooks

  • 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. 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. Action Hooks - Example 1: Event do_action( 'save_post_product' ); CustomizeWoo.com
  • 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
  • 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. 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