Skip to content

Instantly share code, notes, and snippets.

@75nineteen
Last active June 28, 2019 02:30
Show Gist options
  • Save 75nineteen/883d392e508a7745ab6c to your computer and use it in GitHub Desktop.
Save 75nineteen/883d392e508a7745ab6c to your computer and use it in GitHub Desktop.
Another example for building your own custom variables
add_action( 'fue_before_variable_replacements', 'fue_register_variable_replacements', 10, 4);
function fue_register_variable_replacements( $var, $email_data, $fue_email, $queue_item ) {
$variables = array(
'referral_code' => ''
);
if ( isset( $email_data['test'] ) && $email_data['test'] ) {
$variables['referral_code'] = '13221';
if ( !empty( $email_data['order_id'] ) ) {
$order = wc_get_order( $email_data['order_id'] );
$referral_code = get_user_meta( $order->customer_user, '_affiliate_key', true );
if ( !empty( $referral_code ) ) {
$variables['referral_code'] = $referral_code;
}
}
} else {
if ( !empty( $queue_item->order_id ) ) {
$order = wc_get_order( $queue_item->order_id );
$referral_code = get_user_meta( $order->customer_user, '_affiliate_key', true );
if ( !empty( $referral_code ) ) {
$variables['referral_code'] = $referral_code;
}
}
}
$var->register( $variables );
}
@dacgarz
Copy link

dacgarz commented Aug 2, 2017

I am experiencing some issues with the line
$queue_item->order_id;

It seems to be passing an nothing. I just need to identify the order_id, can you help?

@PMiddeldorp
Copy link

I'm having the same problem as dacgarz. Is there an update on this issue? I'm not able to add a custom variable now.

@carlyblack
Copy link

not working for me either. When I add the code and test it on the site it gives me the test data in a preview, but is totally blank on email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment