Created
July 23, 2020 23:44
-
-
Save leroyrosales/a607393539a9fa7ac266fe51320c954b to your computer and use it in GitHub Desktop.
This file contains 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
/** | |
* Add multiple filters to a closure | |
* | |
* @param $tags | |
* @param $function_to_add | |
* @param int $priority | |
* @param int $accepted_args | |
* | |
* @return bool true | |
* https://snippets.khromov.se/adding-multiple-actions-and-filters-using-anonymous-functions-in-wordpress/ | |
*/ | |
function add_filters($tags, $function_to_add, $priority = 10, $accepted_args = 1) | |
{ | |
//If the filter names are not an array, create an array containing one item | |
if(!is_array($tags)) | |
$tags = array($tags); | |
//For each filter name | |
foreach($tags as $index => $tag) | |
add_filter($tag, $function_to_add, (int)(is_array($priority) ? $priority[$index] : $priority), (int)(is_array($accepted_args) ? $accepted_args[$index] : $accepted_args)); | |
return true; | |
} | |
// All filters for booking notifications | |
add_filters(array( | |
// New & Pending Confirmation | |
'woocommerce_booking_in-cart_to_paid', | |
'woocommerce_booking_in-cart_to_pending-confirmation', | |
'woocommerce_booking_unpaid_to_paid', | |
'woocommerce_booking_unpaid_to_pending-confirmation', | |
'woocommerce_booking_confirmed_to_paid', | |
'woocommerce_admin_new_booking', | |
'woocommerce_admin_confirmed', | |
// Confirmed | |
'woocommerce_booking_confirmed', | |
// Pending Confirmation | |
'woocommerce_booking_pending-confirmation', | |
// Cancelled | |
'woocommerce_booking_pending-confirmation_to_cancelled', | |
'woocommerce_booking_confirmed_to_cancelled', | |
'woocommerce_booking_paid_to_cancelled' | |
), function(){ | |
add_filter('woocommerce_email_from_address', function( $from_email ){ return 'email@address.com'; }); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment