Last active
August 22, 2019 10:12
-
-
Save junaidtk/94a0538f696e95baf638fe3ccbd53de0 to your computer and use it in GitHub Desktop.
Some of Dynamics hooks used in the woocommerce
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In woo-commerce there are lot of filter they are dynamically generated for the multiple function use. | |
So these hooks are hard to find and can't be found while searching the woocommerce folder. | |
The below hook is the one of the dynamic hooks used in the woocommerce | |
1) get_property hooks for the woocommerce product class (woocommerce_product_get_price). | |
========================================================= | |
All the get_functions in the WooCommerce product class, like $product->get_price(), | |
use the get_prop() method under the dynamic filter hook | |
This is part of the WC_Data class that WC_Product extends. | |
At the end of get_prop() the filters are applied like this: | |
apply_filters( $this->get_hook_prefix() . $key, $value, $this ); | |
And get_hook_prefix() looks like this: | |
protected function get_hook_prefix() { | |
return 'woocommerce_' . $this->object_type . '_get_'; | |
} | |
So all the get_ methods like get_price(), get_sku(), get_description() etc. | |
will go through a filter with the same format: woocommerce_product_get_{property}. | |
for the get_price() function the hook will be woocommerce_product_get_price. | |
For the new filter, the 2 arguments are the value, $value, and the product, $this. | |
So it doesn't look like you need to change the callback. It should be sufficient to change the hook name. | |
2)woocommerce_billing_fields and woocommerce_shipping_fields | |
============================================================== | |
The above two hooks are created dynamically. The filter is given below. located at class-wc-countries.php file | |
$address_fields = apply_filters( 'woocommerce_' . $type . 'fields', $address_fields, $country ); | |
The above filter is used to billing and shipping fields. | |
3)woocommerce_order_status_pending_to_on-hold etc. | |
==================================================== | |
This is the email trigger while creating the order. | |
It will fire when we chnage the order status from pending to on hold status. | |
For new order the default status is pending and it changes to corresponding status as per the order like | |
'woocommerce_order_status_pending_to_processing' | |
'woocommerce_order_status_pending_to_completed' | |
This hook is dynamically created one. | |
do_action( 'woocommerce_order_status_' . $status_transition['from'] . '_to_' . $status_transition['to']; | |
other related hook is | |
do_action( 'woocommerce_order_status_' . $status_transition['to'] | |
4)woocommerce_email_recipient_new_order for adding additional emails while sending. | |
==================================================================================== | |
This is also dynamically generated hook. It will add additional email for sending email. | |
apply_filters( 'woocommerce_email_recipient_' . $this->id, $this->recipient, $this->object, $this ); | |
example hook contain woocommerce_email_recipient_new_order. This hook add reciepient to new order email | |
eg: new_order, cancelled_order, failed_order etc. | |
Other related hook include. | |
apply_filters( 'woocommerce_email_heading_' . $this->id, | |
$this->format_string( $this->get_option( 'heading', $this->get_default_heading() ) ),$this->object, $this ); | |
apply_filters( 'woocommerce_email_subject_' . $this->id, | |
$this->format_string( $this->get_option( 'subject', $this->get_default_subject() ) ), $this->object, $this ); | |
etc. | |
Reference Links: | |
https://www.mootpoint.org/blog/customising-woocommerce-notification-emails-hooks-filters/ | |
https://www.skyverge.com/blog/add-woocommerce-email-recipients-conditionally/ | |
https://www.skyverge.com/blog/how-to-add-a-custom-woocommerce-email/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment