Last active
April 9, 2018 17:32
-
-
Save Pross/b17d727c29476ad13a23 to your computer and use it in GitHub Desktop.
Small class to add a replacement variable to subscription emails in the Woocommerce Follow Up Emails plugin for WordPress
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 | |
/** | |
* Plugin Name: WooCommerce Follow Up Emails Extra Variable | |
* Description: Add a replacement variable to subscription emails in the Woocommerce Follow Up Emails plugin for WordPress | |
* Version: 1.0 | |
* Author: Pross | |
* Author URI: http://www.pagelines.com | |
* Requires at least: 4.0 | |
* Tested up to: 4.2 | |
* | |
* @author Pross | |
*/ | |
class FUE_Addon_Subscriptions_Extras { | |
/** | |
* The construct, we run our actions.. | |
* | |
*/ | |
function __construct() { | |
add_action( 'fue_before_variable_replacements', array($this, 'register_variable_replacements'), 11, 4 ); | |
add_action( 'fue_email_variables_list', array($this, 'email_variables_list') ); | |
} | |
/** | |
* Register the intended replacements, in this case 'subs_renew_amount' | |
* | |
*/ | |
function register_variable_replacements( $var, $email_data, $email, $queue_item ) { | |
$variables = array( | |
'subs_renew_amount' | |
); | |
$variables = $this->add_variable_replacements( $variables, $email_data, $queue_item, $email ); | |
$var->register( $variables ); | |
} | |
/** | |
* This is where the actual replacement takes place. | |
* In our case we replace subs_renew_amount with the renewal price. | |
* | |
*/ | |
function add_variable_replacements( $variables, $email_data, $queue_item, $email ) { | |
if ( !$queue_item->order_id ) { | |
return $variables; | |
} | |
$order = WC_FUE_Compatibility::wc_get_order( $queue_item->order_id ); | |
if ( !WC_Subscriptions_Order::order_contains_subscription( $order ) ) { | |
return $variables; | |
} | |
$variables['subs_renew_amount'] = wc_price( WC_Subscriptions_Order::get_recurring_total( $order ) ); | |
return $variables; | |
} | |
/** | |
* This function adds the little helper html on the right of the email edit page {subs_renew_amount} | |
* | |
*/ | |
function email_variables_list( $email ) { | |
global $woocommerce; | |
if ( $email->type != 'subscription' ) { | |
return; | |
} | |
?> | |
<li class="var hideable var_subscriptions"><strong>{subs_renew_amount}</strong> <img class="help_tip" title="<?php _e('Renewel Amount', 'follow_up_emails'); ?>" src="<?php echo $woocommerce->plugin_url(); ?>/assets/images/help.png" width="16" height="16" /></li> | |
<?php | |
} | |
} | |
/* | |
* Initiate the class. | |
*/ | |
new FUE_Addon_Subscriptions_Extras; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment