Last active
April 22, 2025 11:20
-
-
Save solaceten/7f03aed8c3b232742b1f6fb7777d8776 to your computer and use it in GitHub Desktop.
Create the custom variable "order.billing_email" for use in automate woo
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
/* | |
// original snippet URL: https://gist.github.com/solaceten/7f03aed8c3b232742b1f6fb7777d8776 | |
// Author solaceten. You are free to do what you want with this but not sell it or make any money from its use. | |
// | |
// Explainer: | |
// Below is a custom function to add a custom variable into automate woo. | |
// This example enables the use of a new variable: order.billing_email - as a variable in the workflow ACTION section, email TO field. | |
// As at Dec 2024, in automatewoo, this variable is working after adding the following code. | |
// | |
// While this code allows you to use the new variable {{ order.billing_email }} in your Workflow, note that in the main queue admin table, | |
// it still displays the customer.email - however, it will send the email to the billing email instead. If you find a way to mofidy this display behaviour, | |
// feel free to add a comment in the GIST snippet | |
// | |
// do not add the above php tag if it's already in your functions file | |
// copy and paste the snippet below to your child theme's functions file or to a dedicated plugin. | |
*/ | |
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
<?php | |
add_filter( 'automatewoo/variables', 'register_order_billing_email_variable' ); | |
/** | |
* Original snippet URL: https://gist.github.com/solaceten/7f03aed8c3b232742b1f6fb7777d8776 | |
* Function to allow us to use the billing email in the AutomateWoo Workflow for follow up emails. | |
* Change path below to where the file in your theme will live | |
* In this example, i'm using a child theme (which you should be doing too!): | |
*/ | |
function register_order_billing_email_variable( $variables ) { | |
// Include the custom class file | |
$variables['order']['billing_email'] = get_stylesheet_directory().'/automatewoo-extension/variable-order-billing-email.php'; | |
// uncomment below to use for debugging (WP_DEBUG mode must be on) | |
//error_log( 'New Custom Variable Registered: order.billing_email' ); | |
return $variables; | |
} |
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
<?php | |
/** | |
* Original snippet URL: https://gist.github.com/solaceten/7f03aed8c3b232742b1f6fb7777d8776 | |
* copy and paste this code to a new file called "variable-order-billing-email.php" under a new folder called "automatewoo-extension" | |
* in your child theme so it looks like this: | |
* themes | |
* - your-child-theme | |
* -- automatewoo-extension | |
* --- variable-order-billing-email.php | |
*/ | |
if ( ! defined( 'ABSPATH' ) ) exit; | |
/** | |
* Class AW_Variable_Order_Billing_Email | |
*/ | |
class My_AutomateWoo_Billing_Email extends AutomateWoo\Variable{ | |
/** | |
* Load admin details for the variable. | |
*/ | |
public function load_admin_details() { | |
$this->description = __( "Displays the billing email address for the order.", 'automatewoo' ); | |
} | |
/** @var bool - whether to allow setting a fallback value for this variable */ | |
public $use_fallback = false; | |
public function get_value( $order, $parameters = [] ) { | |
if ( $order && is_a( $order, 'WC_Order' ) ) { | |
return $order->get_billing_email(); | |
} | |
return 'No email available'; | |
} | |
} | |
return new My_AutomateWoo_Billing_Email(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment