Created
November 21, 2014 23:16
-
-
Save drrobotnik/3dc4a16873a78b16ff76 to your computer and use it in GitHub Desktop.
preview email
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
/** | |
* Open a preview e-mail. | |
* | |
* @return null | |
*/ | |
function previewEmail() { | |
if (is_admin()) { | |
$default_path = WC()->plugin_path() . '/templates/'; | |
$files = scandir($default_path . 'emails'); | |
$exclude = array( '.', '..', 'email-header.php', 'email-footer.php','plain' ); | |
$list = array_diff($files,$exclude); | |
?><form method="get" action="<?php echo site_url(); ?>/wp-admin/admin-ajax.php"> | |
<input type="hidden" name="order" value="2055"> | |
<input type="hidden" name="action" value="previewemail"> | |
<select name="file"> | |
<?php | |
foreach( $list as $item ){ ?> | |
<option value="<?php echo $item; ?>"><?php echo str_replace('.php', '', $item); ?></option> | |
<?php } ?> | |
</select><input type="submit" value="Go"></form><?php | |
global $order; | |
$order = new WC_Order($_GET['order']); | |
wc_get_template( 'emails/email-header.php', array( 'order' => $order ) ); | |
wc_get_template( 'emails/'.$_GET['file'], array( 'order' => $order ) ); | |
wc_get_template( 'emails/email-footer.php', array( 'order' => $order ) ); | |
} | |
return null; | |
} | |
add_action('wp_ajax_previewemail', 'previewEmail'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment