Upgrade to Pro — share decks privately, control downloads, hide ads and more …

March 2017 WooCommerce Meetup - Extending your ...

March 2017 WooCommerce Meetup - Extending your e-commerce store with WooCommerce hooks

Tweet

More Decks by Ahmedabad WordPress Meetup

Transcript

  1. Table of Contents ➢ Why you need to extend your

    E-Commerce Store? ➢ How many ways you can extend your E-Commerce Store with WooCommerce? ➢ What is hooks & Types of hooks? ➢ With example I will demonstrate you how you can extend your E-Commerce store with WooCommerce
  2. You can extend your E-Commerce store in many ways as

    mentioned below: ➢ Extending the Woocommerce template files in your theme. ➢ With the hooks and filters of WooCommerce.
  3. Extending your WooCommerce store with WooCommerce template files in your

    theme ➢ Create woocommerce directory in your theme ➢ You can find a list of all WooCommerce template files here: /wp-content/plugins/woocommerce/templates/ ➢ In this example, if you want to customize this file: /wp-content/plugins/woocommerce/templates/single-product/add-to-cart/simple .php
  4. ➢ We will create below mentioned directory structure in our

    theme's directory. ➢ /wpcontent/themes/twentyseventeen/woocommerce/single-product/add-to-cart/si mple.php. ➢ You can also change the email content with the help of extending WooCommerce template in your theme. Extending your WooCommerce store with WooCommerce template files in your theme
  5. ➢ Hooks are functions that can be applied to an

    Action or a Filter in WordPress. ➢ There are two types of hook: actions and filters. ▪ Action Hooks allow you to insert custom code at various points (wherever the hook is run). ▪ Filter Hooks allow you to manipulate and return a variable which it passes (for instance a product price). ➢ Syntax of the hooks What is Hooks
  6. $tag: (string) (Required) The name of the action to which

    the $function_to_add is hooked. $function_to_add: (callable) (Required) The name of the function you wish to be called. $priority: (int) (Optional) Used to specify the order in which the functions associated with a particular action are executed. Lower numbers correspond with earlier execution, and functions with the same priority are executed in the order in which they were added to the action. Default value: 10 $accepted_args: (int) (Optional) The number of arguments the function accepts. Default value: 1 Syntax of Hooks
  7. Action Hooks If you use a hook to add or

    manipulate code, you can add your custom code to your theme’s functions.php file. To execute your own code, you hook in by using the action hook do_action('action_name');. Here is where to place your code: add_action( 'action_name', 'your_function_name'); function your_function_name() { // Your code }
  8. Filter Hooks Filter hooks are called throughout are code using

    apply_filter( 'filter_name', $variable );. To manipulate the passed variable, you can do something like the following: add_filter( 'filter_name', 'your_function_name' ); function your_function_name( $variable ) { // Your code return $variable; } With filters, you must return a value.
  9. Extending your WooCommerce store with hooks You can get all

    the hooks and filters of WooCommerce from below page ➢ (https://docs.woocommerce.com/wc-apidocs/hook-docs.html)