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

  1. 1. Getting Ready: Filter Hooks CustomizeWoo.com
  2. 2. WordPress Filter Hooks 1/2 Allow you to edit / "filter" content just before this is given back to WordPress CustomizeWoo.com
  3. 3. WordPress Filter Hooks 2/2 tl;dr: if WP/WC provide apply_filters( 'hook_name' ) you can edit that content before it is processed CustomizeWoo.com
  4. 4. Filter Hooks - Example apply_filters( 'woocommerce_product_description_heading', __( 'Description', 'woocommerce' ) ) CustomizeWoo.com
  5. 5. Filter Hooks - Example add_filter( 'woocommerce_product_description_heading', 'edit_heading' ); function edit_heading() { // do something to edit the heading } CustomizeWoo.com
  6. 6. Filter Hooks: apply_filters Syntax apply_filters( 'hook_name', $value, $args ); ● kindly provided by WP/themes/plugins ● $value = filterable content ● $args = variables you can "pass" and use in your hooked function CustomizeWoo.com
  7. 7. Filter Hooks: add_filter Syntax add_filter( 'hook_name', 'func_name', 10, 1 ); ● goes in functions.php @ child theme ● same "hook_name" as per apply_filters ● hooked function ● priority = 10 by default / if omitted ● args = 1 by default / if omitted CustomizeWoo.com
  8. 8. Filter Hooks: function Syntax function func_name( $value, $args ) { // do something to $value return $value; } ● goes in functions.php @ child theme ● return $value back to the system CustomizeWoo.com
  9. 9. Filter Hooks: tl;dr Syntax apply_filters( 'hook_name', $val, $arg1 ); add_filter( 'hook_name', 'func_name', 10, 2 ); function func_name( $val, $arg1 ) { } CustomizeWoo.com
  10. 10. Filter Hooks: WC Example apply_filters( 'woocommerce_checkout_show_terms', true ); add_filter( 'woocommerce_checkout_show_terms', 'no_terms' ); function no_terms( $val ) { $val = false; return $val; } CustomizeWoo.com
  11. 11. Filter Hooks: WC Example apply_filters( 'woocommerce_checkout_show_terms', true ); add_filter( 'woocommerce_checkout_show_terms', 'no_terms' ); function no_terms( $val ) { $val = false; return $val; } CustomizeWoo.com
  12. 12. Filter Hooks: Project Checklist 1. Project Specs e.g. "Edit Add Cart Button Label" 2. Search for apply_filters() 3. Hook your function with add_filter() 4. Write your filter function CustomizeWoo.com
  13. 13. Filter Hooks: Recap ● Help us override WooCommerce etc. without editing core / template files (add_filter() and function go in functions.php @ child theme) ● Not easy to find/code vs do_action() - need lots of practice and smart file search CustomizeWoo.com

×