File manager - Edit - /home/aussies6/public_html/seafoodwarehouse.com.au/wp-content/plugins/custom-woocommerce-emails/custom-woocommerce-emails.php
Back
<?php /** * Plugin Name: Custom Woocommerce Emails * Description: Completely customize every aspect of the emails you send to customers from your Wordpress, Woocommerce Shop. * Author: WPCloudApp.com * Author URI: http://www.WPCloudApp.com * Plugin URI: http://www.WPCloudApp.com * Version: 1.0 * Domain Path: /languages/ * License: GNU General Public License v3.0 * License URI: http://www.gnu.org/licenses/gpl-3.0.html */ if ( !defined( 'ABSPATH' ) ) exit; // Exit if accessed directly /** * Define Constants */ define( 'CUSTOM_WOO_EMAILS_VERSION', '1.0' ); define( 'CUSTOM_WOO_EMAILS_REQUIRED_WOOCOMMERCE_VERSION', '2.3' ); define( 'CUSTOM_WOO_EMAILS_DIR', untrailingslashit( plugin_dir_path( __FILE__ ) ) ); define( 'CUSTOM_WOO_EMAILS_URI', untrailingslashit( plugin_dir_url( __FILE__ ) ) ); define( 'CUSTOM_WOO_EMAILS_PLUGIN_BASENAME', plugin_basename( __FILE__ ) ); /** * Check if plugin is validated */ if (false !== strstr($_SERVER['REQUEST_URI'], 'page=custom_woocommerce_email')) { $resp = Custom_Woo_Email::woocommerce_woo_api(get_option('custom_woocommerce_email_woocommerce_api_key'), get_option('custom_woocommerce_email_woocommerce_api_email'), 'status'); if (!isset($resp->status_check)) { $resp->status_check = 'inactive'; } if ($resp->status_check != 'active' && $_SERVER['REQUEST_URI'] != '/wp-admin/admin.php?page=custom_woocommerce_email-validation') { if (header('Location:' . get_site_url() . '/wp-admin/admin.php?page=custom_woocommerce_email-validation')) { exit; } } } /** * Check if WooCommerce is active, and is required WooCommerce version. */ if ( ! Custom_Woo_Email::is_woocommerce_active() || version_compare( get_option( 'woocommerce_version' ), CUSTOM_WOO_EMAILS_REQUIRED_WOOCOMMERCE_VERSION, '<' ) ){ add_action( 'admin_notices', array( 'Custom_Woo_Email', 'woocommerce_inactive_notice' ) ); return; } /** * Includes */ include_once( 'includes/cwe-woo-back-compat-functions.php' ); include_once( 'includes/cwe-functions.php' ); include_once( 'includes/class-cwe-settings.php' ); include_once( 'cwe-template-woocommerce.php' ); // Template include_once( 'cwe-template-vanilla.php' ); // Template include_once( 'cwe-template-deluxe.php' ); // Template include_once( 'cwe-template-supreme.php' ); // Template /** * Instantiate plugin. */ global $custom_woo_emails; $custom_woo_emails = Custom_Woo_Email::get_instance(); /** * Main Class. */ class Custom_Woo_Email { CONST woo_domain = 'www.wpcloudapp.com'; CONST plugin_id = 'Customize Woocommerce Emails Wordpress Plugin'; private $id = 'custom_woocommerce_email'; private static $instance; /** * Get Instance creates a singleton class that's cached to stop duplicate instances */ public static function get_instance() { if ( !self::$instance ) { self::$instance = new self(); self::$instance->init(); } return self::$instance; } /** * Construct empty on purpose */ private function __construct() {} /** * Init behaves like, and replaces, construct */ public function init() { // Translations add_action( 'init', array( $this, 'load_translation' ) ); // Register email templates. add_action( 'init', array( $this, 'register_email_templates' ), 100 ); // Enqueue Scripts/Styles - in head of admin page add_action( 'admin_enqueue_scripts', array( $this, 'cwe_head_scripts' ) ); // Enqueue Scripts/Styles - in head of email template page add_action( 'cwe_render_template_head_scripts', array( $this, 'cwe_head_scripts' ), 102 ); // Add menu item add_action( 'admin_menu', array( $this, 'admin_menu' ) ); // Ajax saving of options add_action( 'wp_ajax_save_meta', array( $this, 'save_meta' ) ); add_action( 'wp_ajax_nopriv_save_meta', array( $this, 'nopriv_save_meta' ) ); // Ajax saving of options new add_action( 'wp_ajax_save_option', array( $this, 'save_option' ) ); add_action( 'wp_ajax_nopriv_save_option', array( $this, 'nopriv_save_option' ) ); // Ajax send email add_action( 'wp_ajax_cwe_send_email', array( $this, 'send_email' ) ); add_action( 'wp_ajax_nopriv_cwe_send_email', array( $this, 'nopriv_send_email' ) ); // Ajax saving of all edit settings add_action( 'wp_ajax_save_edit_email', array( $this, 'save_edit_email' ) ); add_action( 'wp_ajax_nopriv_save_edit_email', array( $this, 'nopriv_save_edit_email' ) ); // Check Templates add_filter( 'wc_get_template', array( $this, 'cwe_get_template' ), 10, 5 ); //Custom Woo Emails - Admin and Template pages only if ( isset($_REQUEST["page"]) && $_REQUEST["page"] == $this->id ) { // Remove all notifications remove_all_actions( 'admin_notices' ); // Remove admin bar require_once( 'includes/toolbar-removal/wp-toolbar-removal.php'); if ( ! isset( $_REQUEST["cwe_render_email"] ) ) { //Custom Woo Emails - Admin Page only add_action( 'in_admin_header', array( $this, 'cwe_render_admin_page' ) ); } else { //Custom Woo Emails - Template page only add_filter( 'wp_print_scripts', array( $this, 'deregister_all_scripts' ), 101 ); add_action( 'wp_print_scripts', array( $this, 'cwe_head_scripts' ), 102 ); add_action( 'admin_init', array( $this, 'cwe_render_template_page' ) ); } } // Add Button in WooCommerce->Settings->Email add_action( 'woocommerce_settings_tabs_email', array( $this, 'woocommerce_settings_button' ) ); // Setup global template args. add_action( 'woocommerce_before_template_part', array( $this, 'cwe_before_template_setup_args_global' ) , 10, 4 ); add_action( 'woocommerce_after_template_part', array( $this, 'cwe_after_template_setup_args_global' ) , 10, 4 ); // Setup options filtering. add_action( 'woocommerce_before_template_part', array( $this, 'cwe_before_template_filter_options' ) , 10, 4 ); // Modify email headers. add_action( 'woocommerce_email_headers', array( $this, 'cwe_email_headers' ) ); // Complicated method to re-aply inline styling after WooCommerce has, // due to WooCommerce having applied wordwrap 60 to the html before // our css is applied, whcih results in some of the CSS not applying. add_filter( 'wc_get_template', array( $this, 'cwe_globalize_email_object' ), 10, 5 ); add_action( 'woocommerce_mail_content', array( $this, 'cwe_style_inline' ), 85 ); // Other simpler WooCommerce emails - Content. // add_filter( 'woocommerce_email_content_low_stock', array( $this, 'woocommerce_simple_email_content' ), 10, 2 ); // add_filter( 'woocommerce_email_content_no_stock', array( $this, 'woocommerce_simple_email_content' ), 10, 2 ); // add_filter( 'woocommerce_email_content_backorder', array( $this, 'woocommerce_simple_email_content' ), 10, 2 ); // Other simpler WooCommerce emails - Headers. // add_filter( 'woocommerce_email_headers', array( $this, 'woocommerce_simple_email_headers' ), 10, 2 ); } /** * Localization * * @date 20-08-2014 * @since 1.0 */ public static function load_translation() { // Domain ID - used in eg __( 'Text', 'pluginname' ) $domain = 'email-control'; // get the languages locale eg 'en_US' $locale = apply_filters( 'plugin_locale', get_locale(), $domain ); // Look for languages here: wp-content/languages/pluginname/pluginname-en_US.mo load_textdomain( $domain, WP_LANG_DIR . "/{$domain}/{$domain}-{$locale}.mo" ); // Don't mention this location in the docs - but keep it for legacy. // Look for languages here: wp-content/languages/plugins/pluginname-en_US.mo load_textdomain( $domain, WP_LANG_DIR . "/plugins/{$domain}-{$locale}.mo" ); // Look for languages here: wp-content/languages/pluginname-en_US.mo load_textdomain( $domain, WP_LANG_DIR . "/{$domain}-{$locale}.mo" ); // Look for languages here: wp-content/plugins/pluginname/languages/pluginname-en_US.mo load_plugin_textdomain( $domain, FALSE, dirname( plugin_basename( __FILE__ ) ) . "/languages/" ); } /** * Allows hooking by the templates wishing to be initialized * * @date 20-04-2016 * @since 2.36 */ public static function register_email_templates() { // Register email templates. do_action( 'register_email_template' ); } /** * Dergister all scripts & styles * * Deregister all scripts so the email template preview is * css clean and free of other plugins js bugs * * @date 20-08-2014 * @since 1.0 */ function deregister_all_scripts() { global $wp_scripts, $wp_styles; // Dequeue All Scripts if (false != $wp_scripts->queue) { foreach($wp_scripts->queue as $script) { $wp_scripts->dequeue( $script ); // if (isset($wp_scripts->registered[$script])) { // $wp_scripts->registered[$script]->deps = array(); // } } } // Dequeue All Styles if (false != $wp_styles->queue) { foreach($wp_styles->queue as $script) { $wp_styles->dequeue( $script ); // if (isset($wp_styles->registered[$script])) { // $wp_styles->registered[$script]->deps = array(); // } } } } /** * Enqueue CSS and Scripts * * @date 20-08-2014 * @since 1.0 */ public function cwe_head_scripts() { global $woocommerce, $wp_scripts, $current_screen, $pagenow; // All Pages wp_register_style( 'woocommerce_admin', $woocommerce->plugin_url() . '/assets/css/admin.css' ); wp_enqueue_style( 'woocommerce_admin' ); wp_enqueue_script( 'woocommerce_admin' ); wp_register_script( 'jquery-tiptip', $woocommerce->plugin_url() . '/assets/js/jquery-tiptip/jquery.tipTip.js', array('jquery') ); wp_enqueue_script( 'jquery-tiptip' ); // Custom Woo Emails - Admin page only if ( ( isset($_REQUEST["page"]) && $_REQUEST["page"] == $this->id) || ( isset($_REQUEST["page"]) && $_REQUEST["page"] == "wc-settings") || ( isset($_REQUEST["cwe_render_email"]) ) || ( isset($current_screen->id) && $current_screen->id == "shop_order") || ( 'plugins.php' == $pagenow ) ) { // For image uplaoder on settings page_link wp_enqueue_media(); /** * Fontello. */ wp_enqueue_style( 'cxecrt-icon-font', CUSTOM_WOO_EMAILS_URI . '/assets/css/fontello/css/cxectrl-icon-font.css', array(), CUSTOM_WOO_EMAILS_VERSION ); // Custom Woo Emails Custom Scripts wp_register_style( 'email-control', CUSTOM_WOO_EMAILS_URI . '/assets/css/email-control-back-end.css', array(), CUSTOM_WOO_EMAILS_VERSION, 'screen' ); wp_enqueue_style( 'email-control' ); wp_register_script( 'email-control', CUSTOM_WOO_EMAILS_URI . '/assets/js/email-control-back-end.js', array( 'jquery', 'jquery-tiptip', 'iris' ), CUSTOM_WOO_EMAILS_VERSION ); wp_enqueue_script( 'email-control' ); wp_localize_script('email-control', 'custom_woocommerce_email', array( 'home_url' => get_home_url(), 'admin_url' => admin_url(), 'ajaxurl' => admin_url('admin-ajax.php') )); // Open Sans - incase it has not yet wp_enqueue_style( 'open-sans' ); } wp_enqueue_style( 'open-sans' ); // Custom Woo Emails - Template page only if ( ( isset($_REQUEST["page"]) && $_REQUEST["page"] == $this->id ) && isset( $_REQUEST["cwe_render_email"] ) ) { // Load jQuery wp_enqueue_script( 'jquery' ); // Load Dashicons wp_enqueue_style( 'dashicons' ); // Custom Woo Emails Custom Scripts wp_register_style( 'email-control', CUSTOM_WOO_EMAILS_URI . '/assets/css/email-control-back-end.css', array(), CUSTOM_WOO_EMAILS_VERSION, 'screen' ); wp_enqueue_style( 'email-control' ); } if ( 'plugins.php' == $pagenow ) { // Plugin Update JS. wp_enqueue_script( 'email-control-update-js', CUSTOM_WOO_EMAILS_URI . '/assets/js/email-control-update.js', array( 'jquery' ), CUSTOM_WOO_EMAILS_VERSION ); wp_localize_script('email-control-update-js', 'custom_woocommerce_email', array( 'home_url' => get_home_url(), 'admin_url' => admin_url(), 'ajaxurl' => admin_url('admin-ajax.php') )); } } /* * Save option * * @date 20-08-2014 * @since 1.0 */ function save_meta() { /* if ( !wp_verify_nonce( $_REQUEST['nonce'], "save_meta_nonce")) { exit("No naughty business please"); } */ global $current_user; get_currentuserinfo(); $field_name = (isset($_REQUEST["field_name"])) ? sanitize_text_field( $_REQUEST["field_name"] ) : "" ; $field_value = (isset($_REQUEST["field_value"])) ? sanitize_text_field( $_REQUEST["field_value"] ) : "" ; if ( strpos($field_name, "userspecifc") ) { //Save the option specific to the current user update_user_meta( $current_user->ID, $field_name, $field_value ); } else { //Save the option to the global options update_option( $field_name, $field_value ); } die(); } function nopriv_save_meta() { _e('You must be logged in', 'email-control' ); die(); } /* * Save option new * * @date 20-08-2014 * @since 1.0 */ function save_option() { /* if ( !wp_verify_nonce( $_REQUEST['nonce'], "save_option_nonce")) { exit("No naughty business please"); } */ $field_name = (isset($_REQUEST["field_name"])) ? sanitize_text_field( $_REQUEST["field_name"] ) : "" ; $field_value = (isset($_REQUEST["field_value"])) ? sanitize_text_field( $_REQUEST["field_value"] ) : "" ; update_option( $field_name, $field_value ); die(); } function nopriv_save_option() { _e( 'You must be logged in', 'email-control' ); die(); } /* * Ajax send email * * @date 20-08-2014 * @since 1.0 */ public function send_email() { global $order, $woocommerce, $custom_woo_emails; $email_type = sanitize_text_field($_REQUEST['cwe_email_type']); $order_id = sanitize_text_field($_REQUEST['cwe_email_order']); // $email_addresses = $_REQUEST['cwe_email_addresses']; // $email_template_id = $_REQUEST['cwe_email_template']; // Handle button actions if ( !empty( $_REQUEST['cwe_email_type'] ) ) { // Load mailer $mailer = $woocommerce->mailer(); $mails = $mailer->get_emails(); // Ensure gateways are loaded in case they need to insert data into the emails $woocommerce->payment_gateways(); $woocommerce->shipping(); $email_to_send = wc_clean( $_REQUEST['cwe_email_type'] ); if ( !empty( $mails ) ) { foreach ( $mails as $mail ) { if ( $mail->id == $email_to_send ) { // Get the chosen order. $order = new WC_Order( $order_id ); // Add the new custom recipient email address. // add_filter( 'woocommerce_email_recipient_' . $mail->id, array( $this, 'woocommerce_email_recipient' ) ); // Old method. $mail->recipient = ( isset( $_REQUEST['cwe_email_addresses'] ) ? sanitize_email( $_REQUEST['cwe_email_addresses'] ) : NULL ); // Init the mail. $custom_woo_emails->populate_mail_object( $order, $mail ); // Send the mail. $mail->send( $mail->get_recipient(), $mail->get_subject(), $mail->get_content(), $mail->get_headers(), $mail->get_attachments() ); } } } } die(); } function nopriv_send_email() { _e( 'You must be logged in', 'email-control' ); die(); } /* * Filter used to modify the receivers email address so tester can specify their own. */ function woocommerce_email_recipient () { if ( isset( $_REQUEST['cwe_email_addresses'] ) ) { return sanitize_email($_REQUEST['cwe_email_addresses']); } } /* * Ajax send email * * @date 20-08-2014 * @since 1.0 */ function trigger_send_email( $order, $mail, $email_addresses) { $email_addresses = str_replace( " ", "", $email_addresses ); $email_addresses = explode( ",", $email_addresses ); $mail->object = new WC_Order($order); $mail->find[] = '{order_date}'; $mail->replace[] = date_i18n( wc_date_format(), strtotime( $mail->object->order_date ) ); $mail->find[] = '{order_number}'; $mail->replace[] = $mail->object->get_order_number(); $mail->recipient = $mail->object->billing_email; $email_subject = $mail->get_subject(); $email_content = $mail->get_content(); $email_headers = $mail->get_headers(); $email_attachments = $mail->get_attachments(); foreach ($email_addresses as $email_address) { echo $mail->send( $email_address, $email_subject, $email_content, $email_headers, $email_attachments ); } die(); } /* * Save all edit template options. * * @date 20-08-2014 * @since 1.0 */ public function save_edit_email() { $email_type = ($_REQUEST['cwe_email_type']) ? sanitize_text_field( $_REQUEST['cwe_email_type'] ) : false ; $email_id = ($_REQUEST['cwe_email_id']) ? sanitize_text_field( $_REQUEST['cwe_email_id'] ) : false ; $settings = cwe_get_settings( $email_id ); EC_Settings::save_fields( $settings ); die(); } function nopriv_save_edit_email() { _e( 'You must be logged in', 'email-control' ); die(); } /** * Render admin page. * * @date 20-08-2014 * @since 1.0 */ public function cwe_render_admin_page() { require_once( 'pages/cwe-admin-page.php'); } /** * Render template page. * * @date 20-08-2014 * @since 1.0 */ public function cwe_render_template_page() { require_once( 'pages/cwe-template-page.php'); } /** * Add a submenu item to the WooCommerce menu * * @date 20-08-2014 * @since 1.0 */ public function admin_menu() { add_submenu_page( 'woocommerce', __( 'Custom Emails', 'email-control' ), __( 'Custom Emails', 'email-control' ), 'manage_woocommerce', $this->id, array( $this, 'cwe_render_admin_page' ) ); /** * Add menu item for validation */ add_submenu_page( 'woocommerce', __( 'Custom Emails Options', 'email-control' ), __( 'Custom Emails Options', 'email-control' ), 'manage_options', 'custom_woocommerce_email-validation', array( $this, 'plugin_validation_page' )); } /** * Send requests to woocommerce API manager * @param string $key * @param string $email * @param string $request * @return mixed */ static function woocommerce_woo_api($key, $email, $request) { $email_enc = urlencode($email); $instance = md5($key . $email . $_SERVER['SERVER_NAME']); $plugin_id = urlencode(self::plugin_id); $url = "http://" . self::woo_domain . "/?wc-api=am-software-api&request={$request}&email={$email_enc}&licence_key={$key}&product_id={$plugin_id}&instance={$instance}&platform={$_SERVER['SERVER_NAME']}"; $resp = file_get_contents($url); $resp = json_decode($resp); return $resp; } /** * Display validation page */ public function plugin_validation_page() { //activate/deactivate API key if ($_POST) { if ($_POST['status_check'] == 'active') { $woo_request = 'activation'; } else { $woo_request = 'deactivation'; } $resp = self::woocommerce_woo_api(trim($_POST['custom_woocommerce_email_woocommerce_api_key']), trim($_POST['custom_woocommerce_email_woocommerce_api_email']), $woo_request); if (isset($resp->error)) { $notices[] = array('message' => 'Error: ' . $resp->error . ' Code: ' . $resp->code, 'class' => 'notice notice-error is-dismissible'); } else { if ($_POST['status_check'] == 'active') { $notices[] = array('message' => 'Successfully activated', 'class' => 'notice notice-success is-dismissible'); } else { $notices[] = array('message' => 'Successfully deactivated', 'class' => 'notice notice-success is-dismissible'); } } update_option('custom_woocommerce_email_woocommerce_api_key', trim($_POST['custom_woocommerce_email_woocommerce_api_key'])); update_option('custom_woocommerce_email_woocommerce_api_email', trim($_POST['custom_woocommerce_email_woocommerce_api_email'])); } $resp = self::woocommerce_woo_api(get_option('custom_woocommerce_email_woocommerce_api_key'), get_option('custom_woocommerce_email_woocommerce_api_email'), 'status'); if (isset($resp->status_check)) { $status_check = $resp->status_check; } else { $status_check = ''; } ?> <div class="wrap woocommerce"> <h2><?php _e("Options", 'email-control'); ?></h2> <?php if (isset($notices)): foreach ($notices as $notice): ?> <div class='<?= $notice['class']; ?>'> <p><?= $notice['message']; ?></p> </div> <?php endforeach; endif; ?> <form method="post" action="<?php echo str_replace('%7E', '~', $_SERVER['REQUEST_URI']); ?>"> <input type="hidden" name="fp_poster_options_nonce" id="fp_poster_options_nonce" value="<?php echo wp_create_nonce('fp_poster_options_nonce'); ?>" /> <table class="form-table"> <tr> <th scope="row"> </th> <td> Get an API key: <a target="_blank" href="https://www.wpcloudapp.com/shop/wordpress-plugins/customize-woocommerce-emails-wordpress-plugin/">link</a> </td> </tr> <tr> <th scope="row"> <label for="custom_woocommerce_email_woocommerce_api_key">API License Key</label> </th> <td> <?php if ($status_check == 'active'): ?> <?php echo get_option('custom_woocommerce_email_woocommerce_api_key'); ?> <input id="custom_woocommerce_email_woocommerce_api_key" type="hidden" name="custom_woocommerce_email_woocommerce_api_key" value="<?php echo get_option('custom_woocommerce_email_woocommerce_api_key'); ?>"/> <?php else: ?> <input id="custom_woocommerce_email_woocommerce_api_key" type="text" name="custom_woocommerce_email_woocommerce_api_key" value="<?php echo get_option('custom_woocommerce_email_woocommerce_api_key'); ?>"/> <?php endif; ?> </td> </tr> <tr> <th scope="row"> <label for="custom_woocommerce_email_woocommerce_api_email">API License Email</label> </th> <td> <?php if ($status_check == 'active'): ?> <?php echo get_option('custom_woocommerce_email_woocommerce_api_email'); ?> <input id="custom_woocommerce_email_woocommerce_api_email" type="hidden" name="custom_woocommerce_email_woocommerce_api_email" value="<?php echo get_option('custom_woocommerce_email_woocommerce_api_email'); ?>"/> <?php else: ?> <input id="custom_woocommerce_email_woocommerce_api_email" type="text" name="custom_woocommerce_email_woocommerce_api_email" value="<?php echo get_option('custom_woocommerce_email_woocommerce_api_email'); ?>"/> <?php endif; ?> </td> </tr> <tr> <th scope="row"> <label for="custom_woocommerce_email_woocommerce_api_key">Activation status</label> </th> <td> <?= $status_check; ?> </td> </tr> </table> <p class="submit"> <?php if ($status_check == 'active'): ?> <input type="submit" class="button-primary" value="<?php _e('Deactivate plugin') ?>" /> <input type="hidden" name="status_check" value="inactive" /> <?php else: ?> <input type="submit" class="button-primary" value="<?php _e('Activate plugin') ?>" /> <input type="hidden" name="status_check" value="active" /> <?php endif; ?> </p> <input type="hidden" name="action" value="update" /> <input type="hidden" name="page_options" value="custom_woocommerce_email_woocommerce_api_key" /> </form> </div> <?php } /** * Add info and button to WooCommerce->settings->email page * * @date 20-08-2014 * @since 1.0 */ function woocommerce_settings_button($data) { global $woocommerce, $wp_scripts, $current_screen; $cwe_url = ""; $cwe_url .= admin_url(); $cwe_url .= "admin.php"; $cwe_url .= "?"; $cwe_url .= "page=custom_woocommerce_email"; if ( isset($_REQUEST["section"]) ) { if ( class_exists('WC') ) { $mailer = WC()->mailer(); $mails = $mailer->get_emails(); } else{ $mailer = $woocommerce->mailer(); $mails = $mailer->get_emails(); } if ( !empty($mails) ) { foreach ( $mails as $mail ) { $template = str_replace("wc_email_", "", sanitize_text_field($_REQUEST["section"]) ); if ( $mail->id == $template ) { $cwe_url .= "&cwe_email_type=" . $template; } } } } ?> <div class="pe-wc-settings-holder"> <?php if ( isset($_REQUEST["section"]) && $_REQUEST["section"] != "" ) { ?> <!-- Inner Tabs --> <h4>Custom Woo Emails</h4> <p> <a class="button ec" href="<?php echo $cwe_url ?>" target="preview_email">Preview Email</a> <?php _e( "Preview and test emails as they will appear in mail clients when received.", 'email-control' ) ?> </p> <?php } else { ?> <!-- First Tab --> <h3>Custom Woo Emails</h3> <p> <a class="button ec" href="<?php echo $cwe_url ?>" target="preview_email">Preview Email</a> <?php _e( "Preview and test emails as they will appear in mail clients when received.", 'email-control' ) ?> </p> <?php } ?> </div> <?php } /** * Check for and return our template. * * WC 2.2 and above - added this filter recently so can't use until more regular support * * @date 20-08-2014 * @since 1.0 * * @return string Template file location */ function cwe_get_template( $located, $template_name, $args, $template_path, $default_path ) { // error_log( $located ); // return $located; // echo "<br>"; // echo "get_template"; // echo "<br>"; // echo "<br>"; // echo 'located--------------------: ' . $located; // echo "<br>"; // echo 'template_name----------: ' . $template_name; // echo "<br>"; // echo "args------------------------: "; // print_r( $args ); // echo "<br>"; // echo 'template_path-----------: ' . $template_path; // echo "<br>"; // echo 'default_path-------------: ' . $default_path; // echo "<br><br><br><br>"; if ( in_array( 'emails', explode( '/', $template_name ) ) && ! in_array( 'plain', explode( '/', $template_name ) ) ) { global $cwe_email_templates, $woocommerce; // Use the selected template from database $cwe_template_selected = get_option( 'cwe_template' ); // Overide selected template with that passed by preview if ( isset( $_REQUEST["cwe_email_template_preview"] ) ) $cwe_template_selected = wp_kses_post( $_REQUEST["cwe_email_template_preview"] ); if ( is_array( $cwe_email_templates ) && isset( $cwe_template_selected ) && $cwe_template_selected !== false ) { if ( array_key_exists( $cwe_template_selected, $cwe_email_templates ) ) { // It's one of our templates so do custom filters add_filter( 'woocommerce_email_custom_details_header', '__return_empty_string' ); // Remove the header of the customer details. $this_template_pathinfo = pathinfo( $template_name ); $cwe_template_selected; // supreme $this_folder_name = $this_template_pathinfo['dirname']; // emails $this_original_file_name = $this_template_pathinfo['filename'] . '.php'; // email-footer.php $this_modified_file_name = $this_template_pathinfo['filename'] . '-' . $cwe_template_selected . '.php'; // email-footer-supreme.php $this_template_versions = ''; // if ( ! version_compare( WC()->version, '2.4', '>=' ) ) $this_template_versions = '-below-wc2.4'; if ( ! version_compare( WC()->version, '2.5', '>=' ) ) $this_template_versions = '-below-wc2.5'; $this_template = ''; /** * Check the WooCommerce template locations. */ // Check WooCommerce for `emails/email-footer-supreme.php`. // Check WooCommerce for `emails/supreme/email-footer.php`. if ( ! $this_template ) { $this_template = locate_template( array( trailingslashit( $woocommerce->template_path() ) . $this_folder_name . '/' . $this_modified_file_name, trailingslashit( $woocommerce->template_path() ) . $this_folder_name . '/' . $cwe_template_selected . '/' . $this_original_file_name, )); } /** * Check templates-as-plugin locations. */ // Check template-plugin for `templates/emails/email-footer-supreme.php`. if ( ! $this_template ) { $this_template = CUSTOM_WOO_EMAILS_DIR . '/templates' . $this_template_versions . '/' . 'emails' . '/' . $this_modified_file_name; if ( !file_exists($this_template) ) $this_template = false; } // Check template-plugin for `templates/emails/supreme/email-footer.php`. if ( ! $this_template ) { $this_template = CUSTOM_WOO_EMAILS_DIR . '/templates' . $this_template_versions . '/' . 'emails' . '/' . $cwe_template_selected . '/' . $this_original_file_name; if ( !file_exists($this_template) ) $this_template = false; } /** * Check our plugin locations. */ // Check our plugin for `templates/emails/email-footer-supreme.php`. if ( ! $this_template && isset( $cwe_email_templates[$cwe_template_selected]['template_folder'] ) ) { $this_template = trailingslashit( $cwe_email_templates[$cwe_template_selected]['template_folder'] ) . 'emails' . '/' . $this_modified_file_name; if ( !file_exists($this_template) ) $this_template = false; } // Check our plugin for `templates/emails/supreme/email-footer.php`. if ( ! $this_template && isset( $cwe_email_templates[$cwe_template_selected]['template_folder'] ) ) { $this_template = trailingslashit( $cwe_email_templates[$cwe_template_selected]['template_folder'] ) . 'emails' . '/' . $cwe_template_selected . '/' . $this_original_file_name; if ( !file_exists($this_template) ) $this_template = false; } // Else return to what was originally passed - $located. if ( ! $this_template ) { $this_template = $located; } // Set the located as $this_template. $located = $this_template; } } } // echo "<br>"; // echo "get_template"; // echo "<br>"; // echo "<br>"; // echo 'located--------------------: ' . $located; // echo "<br>"; // echo 'template_name----------: ' . $template_name; // echo "<br>"; // echo "args------------------------: "; // print_r( $args ); // echo "<br>"; // echo 'template_path-----------: ' . $template_path; // echo "<br>"; // echo 'default_path-------------: ' . $default_path; // echo "<br><br><br><br>"; return $located; } /** * Modify options before template * * Only if one of the email templates are run, so as not to waste processing time, * and check if REQUEST fields are being posted and rather use those. * * @date 20-08-2014 * @since 1.0 */ function cwe_before_template_filter_options( $template_name, $template_path, $located, $args ) { if ( FALSE !== strrpos( $template_name, 'email' ) ) { // Get active templates. $cwe_template_selected = false; if ( get_option( "cwe_template" ) ) { $cwe_template_selected = get_option( "cwe_template" ); } if ( isset( $_REQUEST['cwe_email_template'] ) ) { $cwe_template_selected = wp_kses_post( $_REQUEST['cwe_email_template'] ); } // Modify if theres preview fields. $settings = cwe_get_settings( $cwe_template_selected ); if ( $settings ) { foreach ( $settings as $setting_key => $setting_value ) { $field_id = $setting_value["id"]; $field_type = $setting_value["type"]; add_filter( "default_option_{$field_id}", array('EC_Settings', 'cwe_default_option') ); add_filter( "option_{$field_id}", create_function( '$field_value', 'return EC_Settings::cwe_render_option("'.$field_id.'", $field_value ); ' ) ); } } // Only do this once, the first time an email template is called. remove_filter( 'woocommerce_before_template_part', array( $this, 'cwe_before_template_filter_options' ) ); } } /** * Push the args into a global. * * To be used in the shortcodes. Has to be done this way while we are * not getting passed $args due to not being able to use WC new filter * in wc_get_template as it was only released late - around 2.2 * * @date 20-08-2014 * @since 2.12 */ function cwe_before_template_setup_args_global( $template_name, $template_path, $located, $args ) { // Only do this for email templates. if ( FALSE !== strrpos( $template_name, 'email' ) ) { global $cwe_template_args; if ( NULL == $cwe_template_args ) { $cwe_template_args = array_merge( $args, array( 'cwe_template_name' => $template_name ) ); // Debugging //echo 'start: ' . $template_name; } } } /** * Remove the args from global on last call to the template function. * * @date 09-02-2015 * @since 2.17 */ function cwe_after_template_setup_args_global( $template_name, $template_path, $located, $args ) { // Only do this for email templates. if ( FALSE !== strrpos( $template_name, 'email' ) ) { global $cwe_template_args; if ( isset( $cwe_template_args['cwe_template_name'] ) && $template_name == $cwe_template_args['cwe_template_name'] ) { $cwe_template_args = NULL; // Debugging //echo 'end: ' . $template_name; } } } /** * Force UTF-8 to email headers * * @date 09-02-2015 * @since 2.17 */ function cwe_email_headers( $headers ) { $headers = str_replace( "\r\n", '; charset=UTF-8' . "\r\n" , $headers ); return $headers; } /** * Format the other simpler WooCommerce emails - Content. */ function woocommerce_simple_email_content( $message ) { ob_start(); wc_get_template('emails/email-header.php' ); echo $message; wc_get_template('emails/email-footer.php' ); return ob_get_clean(); } /** * Format the other simpler WooCommerce emails - Headers. */ function woocommerce_simple_email_headers() { return "Content-Type: text/html; charset=UTF-8\r\n"; } /** * Store the email object in a global so we can access it in the next steps. */ function cwe_globalize_email_object( $located, $template_name, $args, $template_path, $default_path ) { global $cxcwe_cache_email_object, $cxcwe_cache_email_formatting_type; // Only if this is an html & email request. if ( isset( $args['email_heading'] ) && isset( $args['plain_text'] ) && FALSE === $args['plain_text'] ) { add_filter( 'woocommerce_email_styles', array( $this, 'cwe_temporarily_empty_css' ) ); $cxcwe_cache_email_formatting_type = 'html'; } // Disable this, as `$args['email']` is not passed by `wc_get_template_html()` until WC 2.5 // Only if this is an html & email request. /*if ( isset( $args['email']->email_type ) ) { add_filter( 'woocommerce_email_styles', array( $this, 'cwe_temporarily_empty_css' ) ); $cxcwe_cache_email_object = $args['email']; }*/ return $located; } /** * Temporarily stop any CSS being applied inline, so that we can do it all in the next step. */ function cwe_temporarily_empty_css( $css ) { return ''; } /** * Apply CSS inline ourselves. */ function cwe_style_inline( $message ) { global $cxcwe_cache_email_object, $cxcwe_cache_email_formatting_type; if ( isset( $cxcwe_cache_email_formatting_type ) && 'html' == $cxcwe_cache_email_formatting_type ) { // Remove the filter added above that blocks CSS being added before this. remove_filter( 'woocommerce_email_styles', array( $this, 'cwe_temporarily_empty_css' ) ); // Remove the break-line's applied already by WC wordwrap, replace them with a space. $message = str_replace( "\n", " ", $message ); // Apply the CSS - merge it inline. $message = $this->cwe_style_inline_for_old_wc( $message ); // Remove Tabs to neaten up. $message = trim( preg_replace( '/\t+/', ' ', $message ) ); // Now apply wordwrap - it should not break the display any more now that it's done after the CSS is inline-ed. $message = wordwrap( $message, 60 ); // Unset the cache, ready fior next email. unset( $cxcwe_cache_email_formatting_type ); } // Disable this, as `$args['email']` is not passed by `wc_get_template_html()` until WC 2.5 /*if ( isset( $cxcwe_cache_email_object ) ) { // Remove the filter added above that blocks CSS being added before this. remove_filter( 'woocommerce_email_styles', array( $this, 'cwe_temporarily_empty_css' ) ); // Remove the break-line's applied already by WC wordwrap, replace them with a space. $message = str_replace( "\n", " ", $message ); // Apply the CSS - merge it inline. $message = $cxcwe_cache_email_object->style_inline( $message ); // Remove Tabs to neaten up. $message = trim( preg_replace( '/\t+/', ' ', $message ) ); // Now apply wordwrap - it should not break the display any more now that it's done after the CSS is inline-ed. $message = wordwrap( $message, 60 ); // Unset the cache, ready fior next email. unset( $cxcwe_cache_email_object ); }*/ return $message; } /** * Temporarily copied and modified from WC * 'Apply inline styles to dynamic content'. * * @param string|null $content * @return string */ public function cwe_style_inline_for_old_wc( $content ) { // make sure we only inline CSS for html emails if ( class_exists( 'DOMDocument' ) ) { ob_start(); wc_get_template( 'emails/email-styles.php' ); $css = apply_filters( 'woocommerce_email_styles', ob_get_clean() ); // apply CSS styles inline for picky email clients try { $emogrifier = new Emogrifier( $content, $css ); $content = $emogrifier->emogrify(); } catch ( Exception $e ) { $logger = new WC_Logger(); $logger->add( 'emogrifier', $e->getMessage() ); } } return $content; } /** * */ public function populate_mail_object( $order, &$mail ) { global $cxcwe_cache_email_message; // New method of gathering email HTML by pushing the data up into a global. add_action( 'woocommerce_mail_content', array( $this, 'cancel_email_send' ), 90 ); // Force the email to seem enabled in-case it has been tuned off programmatically. $mail->enabled = 'yes'; /** * Get a User ID for the preview. */ // Get the Customer user from the order, or the current user ID if guest. if ( 0 === ( $user_id = (int) get_post_meta( $order->id, '_customer_user', TRUE ) ) ) { $user_id = get_current_user_id(); } $user = get_user_by( 'id', $user_id ); /** * Get a Product ID for the preview. */ // Get a product from the order. If it doesnt exist anymore then get the latest product. $items = $order->get_items(); foreach ( $items as $item ) { $product_id = $item['product_id']; if ( NULL !== get_post( $product_id ) ) break; //$product_variation_id = $item['variation_id']; } if ( NULL === get_post( $product_id ) ){ $products_array = get_posts( array( 'posts_per_page' => 1, 'orderby' => 'date', 'post_type' => 'product', 'post_status' => 'publish', ) ); if ( isset( $products_array[0]->ID ) ){ $product_id = $products_array[0]->ID; } } /** * Generate the required email for use with Sending or Previewing. * * All the email types in all the varying plugins require specific * properties to be set before they generate the email for our * preview, or send a test email. */ $compatabiltiy_warning = FALSE; // Default. switch ( $mail->id ) { /** * WooCommerce (default transactional mails). */ case 'new_order': case 'cancelled_order': case 'customer_processing_order': case 'customer_completed_order': case 'customer_refunded_order': case 'customer_on_hold_order': case 'customer_invoice': case 'failed_order': $mail->object = $order; $mail->find['order-date'] = '{order_date}'; $mail->find['order-number'] = '{order_number}'; $mail->replace['order-date'] = date_i18n( wc_date_format(), strtotime( $mail->object->order_date ) ); $mail->replace['order-number'] = $mail->object->get_order_number(); break; case 'customer_new_account': $mail->object = $user; $mail->user_pass = '{user_pass}'; $mail->user_login = stripslashes( $mail->object->user_login ); $mail->user_email = stripslashes( $mail->object->user_email ); $mail->recipient = $mail->user_email; $mail->password_generated = TRUE; break; case 'customer_note': $mail->object = $order; $mail->customer_note = 'Hello'; $mail->find['order-date'] = '{order_date}'; $mail->find['order-number'] = '{order_number}'; $mail->replace['order-date'] = date_i18n( wc_date_format(), strtotime( $mail->object->order_date ) ); $mail->replace['order-number'] = $mail->object->get_order_number(); break; case 'customer_reset_password': $mail->object = $user; $mail->user_login = $user->user_login; $mail->reset_key = '{{reset-key}}'; break; /** * WooCommerce Wait-list Plugin (from WooCommerce). */ case 'woocommerce_waitlist_mailout': $mail->object = get_product( $product_id ); $mail->find[] = '{product_title}'; $mail->replace[] = $mail->object->get_title(); break; /** * WooCommerce Subscriptions Plugin (from WooCommerce). */ case 'new_renewal_order': case 'new_switch_order': case 'customer_processing_renewal_order': case 'customer_completed_renewal_order': case 'customer_completed_switch_order': case 'customer_renewal_invoice': $mail->object = $order; break; case 'cancelled_subscription': $mail->object = FALSE; $compatabiltiy_warning = TRUE; break; /** * Everything else, including all default WC emails. */ default: $mail->object = $order; $compatabiltiy_warning = TRUE; break; } return $compatabiltiy_warning; } /** * New method of previewing emails. * Stores the email message up in a global, then return an * empty string message which prevents the email sending. */ function cancel_email_send( $message ) { global $cxcwe_cache_email_message; $cxcwe_cache_email_message = $message; return $message; } /** * Check if any conflicting plugins are active, then deactivate ours. * * @since 2.36 */ public static function is_conflicting_plugins_active() { global $cxcwe_plugins_found; $active_plugins = (array) get_option( 'active_plugins', array() ); if ( is_multisite() ) $active_plugins = array_merge( $active_plugins, get_site_option( 'active_sitewide_plugins', array() ) ); // Define the plugins to check for. $plugins_to_check = array( 'woocommerce-email-customizer.php' => 'WooCoomerce Custom Woo Emails by WooThemes', 'yith-woocommerce-email-templates' => 'YITH WooCommerce Email Templates', ); $cxcwe_plugins_found = array(); foreach ( $active_plugins as $active_plugin_key => $active_plugin_value ) { foreach ( $plugins_to_check as $plugins_to_check_key => $plugins_to_check_value ) { if ( FALSE !== strpos( $active_plugin_value, $plugins_to_check_key ) || FALSE !== strpos( $active_plugin_key, $plugins_to_check_key ) ) { // Collect the found plugin. $cxcwe_plugins_found[] = $plugins_to_check[$plugins_to_check_key]; } } } return ! empty( $cxcwe_plugins_found ); } /** * Display Notifications on conflicting plugins active. * * @since 2.36 */ public static function is_conflicting_plugins_active_notice() { global $cxcwe_plugins_found; if ( ! empty( $cxcwe_plugins_found ) ) : ?> <div id="message" class="error"> <p> <?php printf( __( '%sCustom Woo Emails for WooCommerce is inactive due to conflicts%sOur plugin will conflict with the following plugins and cannot be used while they are active: %s', 'email-control' ), '<strong>', '</strong><br>', '<em>' . implode( ', ', $cxcwe_plugins_found ) . '</em>' ); ?> </p> </div> <?php endif; } /** * Is WooCommerce active. */ public static function is_woocommerce_active() { $active_plugins = (array) get_option( 'active_plugins', array() ); if ( is_multisite() ) $active_plugins = array_merge( $active_plugins, get_site_option( 'active_sitewide_plugins', array() ) ); return in_array( 'woocommerce/woocommerce.php', $active_plugins ) || array_key_exists( 'woocommerce/woocommerce.php', $active_plugins ); } /** * Display Notifications on specific criteria. * * @since 2.14 */ public static function woocommerce_inactive_notice() { if ( current_user_can( 'activate_plugins' ) ) : if ( !class_exists( 'WooCommerce' ) ) : ?> <div id="message" class="error"> <p> <?php printf( __( '%sCustom Woo Emails for WooCommerce needs WooCommerce%s %sWooCommerce%s must be active for Custom Woo Emails to work. Please install & activate WooCommerce.', 'email-control' ), '<strong>', '</strong><br>', '<a href="http://wordpress.org/extend/plugins/woocommerce/" target="_blank" >', '</a>' ); ?> </p> </div> <?php elseif ( version_compare( get_option( 'woocommerce_db_version' ), CUSTOM_WOO_EMAILS_REQUIRED_WOOCOMMERCE_VERSION, '<' ) ) : ?> <div id="message" class="error"> <!--<p style="float: right; color: #9A9A9A; font-size: 13px; font-style: italic;">For more information <a href="http://cxthemes.com/plugins/update-notice.html" target="_blank" style="color: inheret;">click here</a></p>--> <p> <?php printf( __( '%sCustom Woo Emails for WooCommerce is inactive%s This version of Custom Woo Emails requires WooCommerce %s or newer. For more information about our WooCommerce version support %sclick here%s.', 'email-control' ), '<strong>', '</strong><br>', CUSTOM_WOO_EMAILS_REQUIRED_WOOCOMMERCE_VERSION, '<a href="https://helpcx.zendesk.com/hc/en-us/articles/202241041/" target="_blank" style="color: inheret;" >', '</a>' ); ?> </p> <div style="clear:both;"></div> </div> <?php endif; endif; } }
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0 |
proxy
|
phpinfo
|
Settings