plugin updates
This commit is contained in:
@@ -1,348 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Main class for Smart Coupons Acknowledgement Email
|
||||
*
|
||||
* @author StoreApps
|
||||
* @since 4.7.8
|
||||
* @version 1.1.0
|
||||
*
|
||||
* @package woocommerce-smart-coupons/includes/emails/
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'WC_SC_Acknowledgement_Email' ) ) {
|
||||
/**
|
||||
* The Smart Coupons Email class
|
||||
*
|
||||
* @extends \WC_SC_Email
|
||||
*/
|
||||
class WC_SC_Acknowledgement_Email extends WC_SC_Email {
|
||||
|
||||
/**
|
||||
* Whether email is a scheduled email or not.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $is_email_scheduled = false;
|
||||
|
||||
/**
|
||||
* Set email defaults
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
$this->id = 'wc_sc_acknowledgement_email';
|
||||
|
||||
$this->customer_email = true;
|
||||
|
||||
// Set email title and description.
|
||||
$this->title = __( 'Smart Coupons - Acknowledgement email', 'woocommerce-smart-coupons' );
|
||||
$this->description = __( 'Send an acknowledgement email to the purchaser. One email per customer.', 'woocommerce-smart-coupons' );
|
||||
|
||||
// Use our plugin templates directory as the template base.
|
||||
$this->template_base = dirname( WC_SC_PLUGIN_FILE ) . '/templates/';
|
||||
|
||||
// Email template location.
|
||||
$this->template_html = 'acknowledgement-email.php';
|
||||
$this->template_plain = 'plain/acknowledgement-email.php';
|
||||
|
||||
$this->placeholders = array(
|
||||
'{coupon_type}' => '',
|
||||
);
|
||||
|
||||
// Trigger for this email.
|
||||
add_action( 'wc_sc_acknowledgement_email_notification', array( $this, 'trigger' ) );
|
||||
|
||||
// Call parent constructor to load any other defaults not explicity defined here.
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default email subject.
|
||||
*
|
||||
* @return string Default email subject
|
||||
*/
|
||||
public function get_default_subject() {
|
||||
return __( '{site_title}: {coupon_type} sent successfully', 'woocommerce-smart-coupons' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default email heading.
|
||||
*
|
||||
* @return string Default email heading
|
||||
*/
|
||||
public function get_default_heading() {
|
||||
return __( '{coupon_type} sent successfully', 'woocommerce-smart-coupons' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default scheduled email subject.
|
||||
*
|
||||
* @return string Default email subject
|
||||
*/
|
||||
public function get_default_scheduled_subject() {
|
||||
return __( '{site_title}: {coupon_type} has been successfully scheduled', 'woocommerce-smart-coupons' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default scheduled email heading.
|
||||
*
|
||||
* @return string Default email heading
|
||||
*/
|
||||
public function get_default_scheduled_heading() {
|
||||
return __( '{coupon_type} has been successfully scheduled', 'woocommerce-smart-coupons' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize Settings Form Fields
|
||||
*/
|
||||
public function init_form_fields() {
|
||||
|
||||
/* translators: %s: list of placeholders */
|
||||
$placeholder_text = sprintf( __( 'This will be used when the setting "WooCommerce > Settings > Smart Coupons > Allow schedule sending of coupons?" is enabled. Available placeholders: %s.', 'woocommerce-smart-coupons' ), '<code>' . implode( '</code>, <code>', array_keys( $this->placeholders ) ) . '</code>' );
|
||||
|
||||
$form_fields = array(
|
||||
'scheduled_subject' => array(
|
||||
'title' => __( 'Scheduled email subject', 'woocommerce-smart-coupons' ),
|
||||
'type' => 'text',
|
||||
'desc_tip' => true,
|
||||
'description' => $placeholder_text,
|
||||
'placeholder' => $this->get_default_scheduled_subject(),
|
||||
'default' => '',
|
||||
),
|
||||
'scheduled_heading' => array(
|
||||
'title' => __( 'Scheduled email heading', 'woocommerce-smart-coupons' ),
|
||||
'type' => 'text',
|
||||
'desc_tip' => true,
|
||||
'description' => $placeholder_text,
|
||||
'placeholder' => $this->get_default_scheduled_heading(),
|
||||
'default' => '',
|
||||
),
|
||||
);
|
||||
|
||||
parent::init_form_fields();
|
||||
|
||||
$this->form_fields = array_merge( $this->form_fields, $form_fields );
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the email should actually be sent and setup email merge variables
|
||||
*
|
||||
* @param array $args Email arguments.
|
||||
*/
|
||||
public function trigger( $args = array() ) {
|
||||
|
||||
$this->email_args = wp_parse_args( $args, $this->email_args );
|
||||
|
||||
if ( ! isset( $this->email_args['email'] ) || empty( $this->email_args['email'] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$email_scheduled_details = ! empty( $this->email_args['scheduled_email'] ) ? $this->email_args['scheduled_email'] : array();
|
||||
$this->is_email_scheduled = ! empty( $email_scheduled_details );
|
||||
|
||||
$this->setup_locale();
|
||||
|
||||
$this->recipient = $this->email_args['email'];
|
||||
|
||||
$order_id = isset( $this->email_args['order_id'] ) ? $this->email_args['order_id'] : 0;
|
||||
|
||||
// Get order object.
|
||||
if ( ! empty( $order_id ) && 0 !== $order_id ) {
|
||||
$order = wc_get_order( $order_id );
|
||||
if ( is_a( $order, 'WC_Order' ) ) {
|
||||
$this->object = $order;
|
||||
}
|
||||
}
|
||||
|
||||
$this->set_placeholders();
|
||||
|
||||
$email_content = $this->get_content();
|
||||
// Replace placeholders with values in the email content.
|
||||
$email_content = ( is_callable( array( $this, 'format_string' ) ) ) ? $this->format_string( $email_content ) : $email_content;
|
||||
|
||||
// Send email.
|
||||
if ( $this->is_enabled() && $this->get_recipient() ) {
|
||||
$this->send( $this->get_recipient(), $this->get_subject(), $email_content, $this->get_headers(), $this->get_attachments() );
|
||||
}
|
||||
|
||||
$this->restore_locale();
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to get email subject.
|
||||
*
|
||||
* @return string Email subject.
|
||||
*/
|
||||
public function get_subject() {
|
||||
if ( true === $this->is_email_scheduled ) {
|
||||
return $this->get_scheduled_subject();
|
||||
}
|
||||
return parent::get_subject();
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to get email subject.
|
||||
*
|
||||
* @return string Email subject.
|
||||
*/
|
||||
public function get_heading() {
|
||||
if ( true === $this->is_email_scheduled ) {
|
||||
return $this->get_scheduled_heading();
|
||||
}
|
||||
return parent::get_heading();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get scheduled email subject.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_scheduled_subject() {
|
||||
return apply_filters(
|
||||
$this->id . '_scheduled_subject',
|
||||
$this->format_string( $this->get_option( 'scheduled_subject', $this->get_default_scheduled_subject() ) ),
|
||||
array(
|
||||
'email_object' => $this->object,
|
||||
'source' => $this,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get scheduled email heading.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_scheduled_heading() {
|
||||
return apply_filters(
|
||||
$this->id . '_scheduled_heading',
|
||||
$this->format_string( $this->get_option( 'scheduled_heading', $this->get_default_scheduled_heading() ) ),
|
||||
array(
|
||||
'email_object' => $this->object,
|
||||
'source' => $this,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to set placeholder variables used in email subject/heading
|
||||
*/
|
||||
public function set_placeholders() {
|
||||
$this->placeholders['{coupon_type}'] = $this->get_coupon_type();
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to load email html content
|
||||
*
|
||||
* @return string Email content html
|
||||
*/
|
||||
public function get_content_html() {
|
||||
|
||||
global $woocommerce_smart_coupon;
|
||||
|
||||
$order = $this->object;
|
||||
|
||||
$email_heading = $this->get_heading();
|
||||
|
||||
$email = isset( $this->email_args['email'] ) ? $this->email_args['email'] : '';
|
||||
$receivers_detail = isset( $this->email_args['receivers_detail'] ) ? $this->email_args['receivers_detail'] : array();
|
||||
$receiver_name = isset( $this->email_args['receiver_name'] ) ? $this->email_args['receiver_name'] : '';
|
||||
$receiver_count = isset( $this->email_args['receiver_count'] ) ? $this->email_args['receiver_count'] : 0;
|
||||
$email_scheduled_details = isset( $this->email_args['scheduled_email'] ) ? $this->email_args['scheduled_email'] : array();
|
||||
$contains_core_coupons = ( isset( $this->email_args['contains_core_coupons'] ) && 'yes' === $this->email_args['contains_core_coupons'] ) ? $this->email_args['contains_core_coupons'] : 'no';
|
||||
|
||||
$default_path = $this->template_base;
|
||||
$template_path = $woocommerce_smart_coupon->get_template_base_dir( $this->template_html );
|
||||
|
||||
ob_start();
|
||||
|
||||
wc_get_template(
|
||||
$this->template_html,
|
||||
array(
|
||||
'email' => $email,
|
||||
'email_heading' => $email_heading,
|
||||
'order' => $order,
|
||||
'receivers_detail' => $receivers_detail,
|
||||
'gift_certificate_receiver_name' => $receiver_name,
|
||||
'receiver_count' => $receiver_count,
|
||||
'email_scheduled_details' => $email_scheduled_details,
|
||||
'contains_core_coupons' => $contains_core_coupons,
|
||||
),
|
||||
$template_path,
|
||||
$default_path
|
||||
);
|
||||
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to load email plain content
|
||||
*
|
||||
* @return string Email plain content
|
||||
*/
|
||||
public function get_content_plain() {
|
||||
|
||||
global $woocommerce_smart_coupon;
|
||||
|
||||
$order = $this->object;
|
||||
$email_heading = $this->get_heading();
|
||||
|
||||
$email = isset( $this->email_args['email'] ) ? $this->email_args['email'] : '';
|
||||
$receivers_detail = isset( $this->email_args['receivers_detail'] ) ? $this->email_args['receivers_detail'] : array();
|
||||
$receiver_name = isset( $this->email_args['receiver_name'] ) ? $this->email_args['receiver_name'] : '';
|
||||
$receiver_count = isset( $this->email_args['receiver_count'] ) ? $this->email_args['receiver_count'] : 0;
|
||||
$email_scheduled_details = isset( $this->email_args['scheduled_email'] ) ? $this->email_args['scheduled_email'] : array();
|
||||
$contains_core_coupons = ( isset( $this->email_args['contains_core_coupons'] ) && 'yes' === $this->email_args['contains_core_coupons'] ) ? $this->email_args['contains_core_coupons'] : 'no';
|
||||
|
||||
$default_path = $this->template_base;
|
||||
$template_path = $woocommerce_smart_coupon->get_template_base_dir( $this->template_html );
|
||||
|
||||
ob_start();
|
||||
|
||||
wc_get_template(
|
||||
$this->template_plain,
|
||||
array(
|
||||
'email' => $email,
|
||||
'email_heading' => $email_heading,
|
||||
'order' => $order,
|
||||
'receivers_detail' => $receivers_detail,
|
||||
'gift_certificate_receiver_name' => $receiver_name,
|
||||
'receiver_count' => $receiver_count,
|
||||
'email_scheduled_details' => $email_scheduled_details,
|
||||
'contains_core_coupons' => $contains_core_coupons,
|
||||
),
|
||||
$template_path,
|
||||
$default_path
|
||||
);
|
||||
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to get coupon type for current coupon being sent.
|
||||
*
|
||||
* @return string $coupon_type Coupon type.
|
||||
*/
|
||||
public function get_coupon_type() {
|
||||
|
||||
global $store_credit_label;
|
||||
|
||||
$receiver_count = isset( $this->email_args['receiver_count'] ) ? $this->email_args['receiver_count'] : 0;
|
||||
$singular = ( ! empty( $store_credit_label['singular'] ) ) ? ucwords( $store_credit_label['singular'] ) : __( 'Gift card', 'woocommerce-smart-coupons' );
|
||||
$plural = ( ! empty( $store_credit_label['plural'] ) ) ? ucwords( $store_credit_label['plural'] ) : __( 'Gift cards', 'woocommerce-smart-coupons' );
|
||||
$coupon_type = ( $receiver_count > 1 ) ? $plural : $singular;
|
||||
$contains_core_coupons = ( isset( $this->email_args['contains_core_coupons'] ) && 'yes' === $this->email_args['contains_core_coupons'] ) ? $this->email_args['contains_core_coupons'] : 'no';
|
||||
|
||||
if ( 'yes' === $contains_core_coupons ) {
|
||||
$coupon_type = _n( 'Coupon', 'Coupons', $receiver_count, 'woocommerce-smart-coupons' );
|
||||
}
|
||||
|
||||
return $coupon_type;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,265 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Main class for Smart Coupons Email
|
||||
*
|
||||
* @author StoreApps
|
||||
* @since 4.4.1
|
||||
* @version 1.2.2
|
||||
*
|
||||
* @package woocommerce-smart-coupons/includes/emails/
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'WC_SC_Combined_Email_Coupon' ) ) {
|
||||
/**
|
||||
* The Smart Coupons Combined Email class
|
||||
*
|
||||
* @extends \WC_SC_Email
|
||||
*/
|
||||
class WC_SC_Combined_Email_Coupon extends WC_SC_Email {
|
||||
|
||||
/**
|
||||
* Set email defaults
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
$this->id = 'wc_sc_combined_email_coupon';
|
||||
|
||||
$this->customer_email = true;
|
||||
|
||||
// Set email title and description.
|
||||
$this->title = __( 'Smart Coupons - Combined auto generated coupons email', 'woocommerce-smart-coupons' );
|
||||
$this->description = __( 'Send only one email instead of multiple emails when multiple coupons are generated per recipient.', 'woocommerce-smart-coupons' );
|
||||
|
||||
// Use our plugin templates directory as the template base.
|
||||
$this->template_base = dirname( WC_SC_PLUGIN_FILE ) . '/templates/';
|
||||
|
||||
// Email template location.
|
||||
$this->template_html = 'combined-email.php';
|
||||
$this->template_plain = 'plain/combined-email.php';
|
||||
|
||||
$this->placeholders = array(
|
||||
'{sender_name}' => '',
|
||||
);
|
||||
|
||||
// Trigger for this email.
|
||||
add_action( 'wc_sc_combined_email_coupon_notification', array( $this, 'trigger' ) );
|
||||
|
||||
// Call parent constructor to load any other defaults not explicity defined here.
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default email subject.
|
||||
*
|
||||
* @return string Default email subject
|
||||
*/
|
||||
public function get_default_subject() {
|
||||
return __( '{site_title}: Congratulations! You\'ve received coupons from {sender_name}', 'woocommerce-smart-coupons' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default email heading.
|
||||
*
|
||||
* @return string Default email heading
|
||||
*/
|
||||
public function get_default_heading() {
|
||||
return __( 'You have received coupons.', 'woocommerce-smart-coupons' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the email should actually be sent and setup email merge variables
|
||||
*
|
||||
* @param array $args Email arguments.
|
||||
*/
|
||||
public function trigger( $args = array() ) {
|
||||
|
||||
$this->email_args = wp_parse_args( $args, $this->email_args );
|
||||
|
||||
if ( ! isset( $this->email_args['email'] ) || empty( $this->email_args['email'] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->setup_locale();
|
||||
|
||||
$this->recipient = $this->email_args['email'];
|
||||
|
||||
$order_id = isset( $this->email_args['order_id'] ) ? $this->email_args['order_id'] : 0;
|
||||
|
||||
// Get order object.
|
||||
if ( ! empty( $order_id ) && 0 !== $order_id ) {
|
||||
$order = wc_get_order( $order_id );
|
||||
if ( is_a( $order, 'WC_Order' ) ) {
|
||||
$this->object = $order;
|
||||
}
|
||||
}
|
||||
|
||||
$this->set_placeholders();
|
||||
|
||||
$email_content = $this->get_content();
|
||||
// Replace placeholders with values in the email content.
|
||||
$email_content = ( is_callable( array( $this, 'format_string' ) ) ) ? $this->format_string( $email_content ) : $email_content;
|
||||
|
||||
// Send email.
|
||||
if ( $this->is_enabled() && $this->get_recipient() ) {
|
||||
$this->send( $this->get_recipient(), $this->get_subject(), $email_content, $this->get_headers(), $this->get_attachments() );
|
||||
}
|
||||
|
||||
$this->restore_locale();
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to set placeholder variables used in email subject/heading
|
||||
*/
|
||||
public function set_placeholders() {
|
||||
$this->placeholders['{sender_name}'] = $this->get_sender_name();
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to load email html content
|
||||
*
|
||||
* @return string Email content html
|
||||
*/
|
||||
public function get_content_html() {
|
||||
|
||||
global $woocommerce_smart_coupon;
|
||||
|
||||
$order = $this->object;
|
||||
$url = $this->get_url();
|
||||
$email_heading = $this->get_heading();
|
||||
|
||||
$sender = '';
|
||||
$from = '';
|
||||
|
||||
$is_gift = isset( $this->email_args['is_gift'] ) ? $this->email_args['is_gift'] : '';
|
||||
|
||||
if ( 'yes' === $is_gift ) {
|
||||
$sender_name = $this->get_sender_name();
|
||||
$sender_email = $this->get_sender_email();
|
||||
if ( ! empty( $sender_name ) && ! empty( $sender_email ) ) {
|
||||
$sender = $sender_name . ' (' . $sender_email . ') ';
|
||||
$from = ' ' . __( 'from', 'woocommerce-smart-coupons' ) . ' ';
|
||||
}
|
||||
}
|
||||
|
||||
$email = isset( $this->email_args['email'] ) ? $this->email_args['email'] : '';
|
||||
$receiver_details = isset( $this->email_args['receiver_details'] ) ? $this->email_args['receiver_details'] : '';
|
||||
|
||||
$design = get_option( 'wc_sc_setting_coupon_design', 'basic' );
|
||||
$background_color = get_option( 'wc_sc_setting_coupon_background_color', '#39cccc' );
|
||||
$foreground_color = get_option( 'wc_sc_setting_coupon_foreground_color', '#30050b' );
|
||||
$third_color = get_option( 'wc_sc_setting_coupon_third_color', '#39cccc' );
|
||||
|
||||
$show_coupon_description = get_option( 'smart_coupons_show_coupon_description', 'no' );
|
||||
|
||||
$valid_designs = $woocommerce_smart_coupon->get_valid_coupon_designs();
|
||||
|
||||
if ( ! in_array( $design, $valid_designs, true ) ) {
|
||||
$design = 'basic';
|
||||
}
|
||||
|
||||
$design = ( 'custom-design' !== $design ) ? 'email-coupon' : $design;
|
||||
|
||||
$coupon_styles = $woocommerce_smart_coupon->get_coupon_styles( $design, array( 'is_email' => 'yes' ) );
|
||||
|
||||
$default_path = $this->template_base;
|
||||
$template_path = $woocommerce_smart_coupon->get_template_base_dir( $this->template_html );
|
||||
|
||||
ob_start();
|
||||
|
||||
wc_get_template(
|
||||
$this->template_html,
|
||||
array(
|
||||
'email' => $email,
|
||||
'email_heading' => $email_heading,
|
||||
'order' => $order,
|
||||
'url' => $url,
|
||||
'from' => $from,
|
||||
'background_color' => $background_color,
|
||||
'foreground_color' => $foreground_color,
|
||||
'third_color' => $third_color,
|
||||
'coupon_styles' => $coupon_styles,
|
||||
'sender' => $sender,
|
||||
'receiver_details' => $receiver_details,
|
||||
'show_coupon_description' => $show_coupon_description,
|
||||
'design' => $design,
|
||||
),
|
||||
$template_path,
|
||||
$default_path
|
||||
);
|
||||
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to load email plain content
|
||||
*
|
||||
* @return string Email plain content
|
||||
*/
|
||||
public function get_content_plain() {
|
||||
|
||||
global $woocommerce_smart_coupon;
|
||||
|
||||
$order = $this->object;
|
||||
$url = $this->get_url();
|
||||
$email_heading = $this->get_heading();
|
||||
|
||||
$sender = '';
|
||||
$from = '';
|
||||
|
||||
$is_gift = isset( $this->email_args['is_gift'] ) ? $this->email_args['is_gift'] : '';
|
||||
|
||||
if ( 'yes' === $is_gift ) {
|
||||
$sender_name = $this->get_sender_name();
|
||||
$sender_email = $this->get_sender_email();
|
||||
if ( ! empty( $sender_name ) && ! empty( $sender_email ) ) {
|
||||
$sender = $sender_name . ' (' . $sender_email . ') ';
|
||||
$from = ' ' . __( 'from', 'woocommerce-smart-coupons' ) . ' ';
|
||||
}
|
||||
}
|
||||
|
||||
$email = isset( $this->email_args['email'] ) ? $this->email_args['email'] : '';
|
||||
$receiver_details = isset( $this->email_args['receiver_details'] ) ? $this->email_args['receiver_details'] : '';
|
||||
|
||||
$default_path = $this->template_base;
|
||||
$template_path = $woocommerce_smart_coupon->get_template_base_dir( $this->template_plain );
|
||||
|
||||
ob_start();
|
||||
|
||||
wc_get_template(
|
||||
$this->template_plain,
|
||||
array(
|
||||
'email' => $email,
|
||||
'email_heading' => $email_heading,
|
||||
'order' => $order,
|
||||
'url' => $url,
|
||||
'from' => $from,
|
||||
'sender' => $sender,
|
||||
'receiver_details' => $receiver_details,
|
||||
),
|
||||
$template_path,
|
||||
$default_path
|
||||
);
|
||||
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to update SC admin email settings when WC email settings get updated
|
||||
*/
|
||||
public function process_admin_options() {
|
||||
// Save regular options.
|
||||
parent::process_admin_options();
|
||||
|
||||
$is_email_enabled = $this->get_field_value( 'enabled', $this->form_fields['enabled'] );
|
||||
|
||||
if ( ! empty( $is_email_enabled ) ) {
|
||||
update_option( 'smart_coupons_combine_emails', $is_email_enabled, 'no' );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,506 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Main class for Smart Coupons Email
|
||||
*
|
||||
* @author StoreApps
|
||||
* @since 4.4.1
|
||||
* @version 1.6.0
|
||||
*
|
||||
* @package woocommerce-smart-coupons/includes/emails/
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'WC_SC_Email_Coupon' ) ) {
|
||||
/**
|
||||
* The Smart Coupons Email class
|
||||
*
|
||||
* @extends \WC_SC_Email
|
||||
*/
|
||||
class WC_SC_Email_Coupon extends WC_SC_Email {
|
||||
|
||||
/**
|
||||
* Set email defaults
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
$this->id = 'wc_sc_email_coupon';
|
||||
|
||||
$this->customer_email = true;
|
||||
|
||||
// Set email title and description.
|
||||
$this->title = __( 'Smart Coupons - Auto generated coupon email', 'woocommerce-smart-coupons' );
|
||||
$this->description = __( 'Email auto generated coupon to recipients. One email per coupon.', 'woocommerce-smart-coupons' );
|
||||
|
||||
// Use our plugin templates directory as the template base.
|
||||
$this->template_base = dirname( WC_SC_PLUGIN_FILE ) . '/templates/';
|
||||
|
||||
// Email template location.
|
||||
$this->template_html = 'email.php';
|
||||
$this->template_plain = 'plain/email.php';
|
||||
|
||||
$this->placeholders = array(
|
||||
'{coupon_code}' => '',
|
||||
'{coupon_type}' => '',
|
||||
'{coupon_value}' => '',
|
||||
'{sender_name}' => '',
|
||||
);
|
||||
|
||||
// Trigger for this email.
|
||||
add_action( 'wc_sc_email_coupon_notification', array( $this, 'trigger' ) );
|
||||
|
||||
// Call parent constructor to load any other defaults not explicity defined here.
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default email subject.
|
||||
*
|
||||
* @return string Default email subject
|
||||
*/
|
||||
public function get_default_subject() {
|
||||
return __( '{site_title}: Congratulations! You\'ve received a {coupon_type} from {sender_name}', 'woocommerce-smart-coupons' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default email heading.
|
||||
*
|
||||
* @return string Default email heading
|
||||
*/
|
||||
public function get_default_heading() {
|
||||
return __( 'You have received a {coupon_type} {coupon_value}', 'woocommerce-smart-coupons' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the email should actually be sent and setup email merge variables
|
||||
*
|
||||
* @param array $args Email arguments.
|
||||
*/
|
||||
public function trigger( $args = array() ) {
|
||||
|
||||
$this->email_args = wp_parse_args( $args, $this->email_args );
|
||||
|
||||
if ( ! isset( $this->email_args['email'] ) || empty( $this->email_args['email'] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->setup_locale();
|
||||
|
||||
$this->recipient = $this->email_args['email'];
|
||||
|
||||
$order_id = isset( $this->email_args['order_id'] ) ? $this->email_args['order_id'] : 0;
|
||||
|
||||
// Get order object.
|
||||
if ( ! empty( $order_id ) && 0 !== $order_id ) {
|
||||
$order = wc_get_order( $order_id );
|
||||
if ( is_a( $order, 'WC_Order' ) ) {
|
||||
$this->object = $order;
|
||||
}
|
||||
}
|
||||
|
||||
$this->set_placeholders();
|
||||
|
||||
$email_content = $this->get_content();
|
||||
// Replace placeholders with values in the email content.
|
||||
$email_content = ( is_callable( array( $this, 'format_string' ) ) ) ? $this->format_string( $email_content ) : $email_content;
|
||||
|
||||
// Send email.
|
||||
if ( $this->is_enabled() && $this->get_recipient() ) {
|
||||
$this->send( $this->get_recipient(), $this->get_subject(), $email_content, $this->get_headers(), $this->get_attachments() );
|
||||
}
|
||||
|
||||
$this->restore_locale();
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to set placeholder variables used in email subject/heading
|
||||
*/
|
||||
public function set_placeholders() {
|
||||
$this->placeholders['{coupon_code}'] = $this->get_coupon_code();
|
||||
$this->placeholders['{coupon_type}'] = $this->get_coupon_type();
|
||||
$this->placeholders['{coupon_value}'] = $this->get_coupon_value();
|
||||
$this->placeholders['{coupon_expiry}'] = $this->get_coupon_expiry();
|
||||
$this->placeholders['{sender_name}'] = $this->get_sender_name();
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to get coupon expiry date/time for current coupon being sent.
|
||||
*
|
||||
* @return string $coupon_expiry Coupon expiry.
|
||||
*/
|
||||
public function get_coupon_expiry() {
|
||||
|
||||
global $woocommerce_smart_coupon;
|
||||
|
||||
$coupon_expiry = '';
|
||||
$coupon = isset( $this->email_args['coupon'] ) ? $this->email_args['coupon'] : '';
|
||||
|
||||
if ( empty( $coupon ) ) {
|
||||
return $coupon_expiry;
|
||||
}
|
||||
|
||||
$coupon_code = ( ! empty( $coupon['code'] ) ) ? $coupon['code'] : '';
|
||||
if ( empty( $coupon_code ) ) {
|
||||
return $coupon_expiry;
|
||||
}
|
||||
|
||||
$_coupon = new WC_Coupon( $coupon_code );
|
||||
if ( $woocommerce_smart_coupon->is_wc_gte_30() ) {
|
||||
$coupon_id = ( is_object( $_coupon ) && is_callable( array( $_coupon, 'get_id' ) ) ) ? $_coupon->get_id() : 0;
|
||||
$expiry_date = ( is_object( $_coupon ) && is_callable( array( $_coupon, 'get_date_expires' ) ) ) ? $_coupon->get_date_expires() : '';
|
||||
} else {
|
||||
$coupon_id = ( ! empty( $_coupon->id ) ) ? $_coupon->id : 0;
|
||||
$expiry_date = ( ! empty( $_coupon->expiry_date ) ) ? $_coupon->expiry_date : '';
|
||||
}
|
||||
|
||||
if ( ! empty( $expiry_date ) ) {
|
||||
if ( $woocommerce_smart_coupon->is_wc_gte_30() && $expiry_date instanceof WC_DateTime ) {
|
||||
$expiry_date = ( is_callable( array( $expiry_date, 'getTimestamp' ) ) ) ? $expiry_date->getTimestamp() : null;
|
||||
} elseif ( ! is_int( $expiry_date ) ) {
|
||||
$expiry_date = strtotime( $expiry_date );
|
||||
}
|
||||
|
||||
if ( ! empty( $expiry_date ) && is_int( $expiry_date ) ) {
|
||||
$expiry_time = (int) $woocommerce_smart_coupon->get_post_meta( $coupon_id, 'wc_sc_expiry_time', true );
|
||||
if ( ! empty( $expiry_time ) ) {
|
||||
$expiry_date += $expiry_time; // Adding expiry time to expiry date.
|
||||
}
|
||||
}
|
||||
$coupon_expiry = $woocommerce_smart_coupon->get_expiration_format( $expiry_date );
|
||||
} else {
|
||||
$coupon_expiry = esc_html__( 'Never expires', 'woocommerce-smart-coupons' );
|
||||
}
|
||||
|
||||
return $coupon_expiry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to load email html content
|
||||
*
|
||||
* @return string Email content html
|
||||
*/
|
||||
public function get_content_html() {
|
||||
|
||||
global $woocommerce_smart_coupon;
|
||||
|
||||
$order = $this->object;
|
||||
$url = $this->get_url();
|
||||
$email_heading = $this->get_heading();
|
||||
|
||||
$sender = '';
|
||||
$from = '';
|
||||
|
||||
$is_gift = isset( $this->email_args['is_gift'] ) ? $this->email_args['is_gift'] : '';
|
||||
|
||||
if ( 'yes' === $is_gift ) {
|
||||
$sender_name = $this->get_sender_name();
|
||||
$sender_email = $this->get_sender_email();
|
||||
if ( ! empty( $sender_name ) && ! empty( $sender_email ) ) {
|
||||
$sender = $sender_name . ' (' . $sender_email . ') ';
|
||||
$from = ' ' . __( 'from', 'woocommerce-smart-coupons' ) . ' ';
|
||||
}
|
||||
}
|
||||
|
||||
$email = isset( $this->email_args['email'] ) ? $this->email_args['email'] : '';
|
||||
$message_from_sender = isset( $this->email_args['message_from_sender'] ) ? $this->email_args['message_from_sender'] : '';
|
||||
$coupon_code = isset( $this->email_args['coupon']['code'] ) ? $this->email_args['coupon']['code'] : '';
|
||||
|
||||
$design = get_option( 'wc_sc_setting_coupon_design', 'basic' );
|
||||
$background_color = get_option( 'wc_sc_setting_coupon_background_color', '#39cccc' );
|
||||
$foreground_color = get_option( 'wc_sc_setting_coupon_foreground_color', '#30050b' );
|
||||
$third_color = get_option( 'wc_sc_setting_coupon_third_color', '#39cccc' );
|
||||
|
||||
$show_coupon_description = get_option( 'smart_coupons_show_coupon_description', 'no' );
|
||||
|
||||
$valid_designs = $woocommerce_smart_coupon->get_valid_coupon_designs();
|
||||
|
||||
if ( ! in_array( $design, $valid_designs, true ) ) {
|
||||
$design = 'basic';
|
||||
}
|
||||
|
||||
$design = ( 'custom-design' !== $design ) ? 'email-coupon' : $design;
|
||||
|
||||
$coupon_styles = $woocommerce_smart_coupon->get_coupon_styles( $design, array( 'is_email' => 'yes' ) );
|
||||
|
||||
$default_path = $this->template_base;
|
||||
$template_path = $woocommerce_smart_coupon->get_template_base_dir( $this->template_html );
|
||||
|
||||
ob_start();
|
||||
|
||||
wc_get_template(
|
||||
$this->template_html,
|
||||
array(
|
||||
'email' => $email,
|
||||
'email_heading' => $email_heading,
|
||||
'order' => $order,
|
||||
'url' => $url,
|
||||
'message_from_sender' => $message_from_sender,
|
||||
'from' => $from,
|
||||
'coupon_code' => $coupon_code,
|
||||
'background_color' => $background_color,
|
||||
'foreground_color' => $foreground_color,
|
||||
'third_color' => $third_color,
|
||||
'coupon_styles' => $coupon_styles,
|
||||
'sender' => $sender,
|
||||
'design' => $design,
|
||||
'show_coupon_description' => $show_coupon_description,
|
||||
),
|
||||
$template_path,
|
||||
$default_path
|
||||
);
|
||||
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to load email plain content
|
||||
*
|
||||
* @return string Email plain content
|
||||
*/
|
||||
public function get_content_plain() {
|
||||
|
||||
global $woocommerce_smart_coupon;
|
||||
|
||||
$order = $this->object;
|
||||
$url = $this->get_url();
|
||||
$email_heading = $this->get_heading();
|
||||
|
||||
$sender = '';
|
||||
$from = '';
|
||||
|
||||
$is_gift = isset( $this->email_args['is_gift'] ) ? $this->email_args['is_gift'] : '';
|
||||
|
||||
if ( 'yes' === $is_gift ) {
|
||||
$sender_name = $this->get_sender_name();
|
||||
$sender_email = $this->get_sender_email();
|
||||
if ( ! empty( $sender_name ) && ! empty( $sender_email ) ) {
|
||||
$sender = $sender_name . ' (' . $sender_email . ') ';
|
||||
$from = ' ' . __( 'from', 'woocommerce-smart-coupons' ) . ' ';
|
||||
}
|
||||
}
|
||||
|
||||
$email = isset( $this->email_args['email'] ) ? $this->email_args['email'] : '';
|
||||
$message_from_sender = isset( $this->email_args['message_from_sender'] ) ? $this->email_args['message_from_sender'] : '';
|
||||
$coupon_code = isset( $this->email_args['coupon']['code'] ) ? $this->email_args['coupon']['code'] : '';
|
||||
|
||||
$default_path = $this->template_base;
|
||||
$template_path = $woocommerce_smart_coupon->get_template_base_dir( $this->template_plain );
|
||||
|
||||
ob_start();
|
||||
|
||||
wc_get_template(
|
||||
$this->template_plain,
|
||||
array(
|
||||
'email' => $email,
|
||||
'email_heading' => $email_heading,
|
||||
'order' => $order,
|
||||
'url' => $url,
|
||||
'message_from_sender' => $message_from_sender,
|
||||
'from' => $from,
|
||||
'coupon_code' => $coupon_code,
|
||||
'sender' => $sender,
|
||||
),
|
||||
$template_path,
|
||||
$default_path
|
||||
);
|
||||
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get coupon code
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_coupon_code() {
|
||||
|
||||
$coupon_code = isset( $this->email_args['coupon']['code'] ) ? $this->email_args['coupon']['code'] : '';
|
||||
|
||||
return $coupon_code;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get coupon value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_coupon_value() {
|
||||
|
||||
global $woocommerce_smart_coupon, $store_credit_label;
|
||||
|
||||
$coupon = isset( $this->email_args['coupon'] ) ? $this->email_args['coupon'] : '';
|
||||
|
||||
if ( empty( $coupon ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$order_id = isset( $this->email_args['order_id'] ) ? $this->email_args['order_id'] : 0;
|
||||
$order = ( ! empty( $order_id ) ) ? wc_get_order( $order_id ) : null;
|
||||
|
||||
$wc_price_args = array(
|
||||
'currency' => is_callable( array( $order, 'get_currency' ) ) ? $order->get_currency() : '',
|
||||
);
|
||||
|
||||
$discount_type = isset( $this->email_args['discount_type'] ) ? $this->email_args['discount_type'] : '';
|
||||
$is_gift = isset( $this->email_args['is_gift'] ) ? $this->email_args['is_gift'] : '';
|
||||
|
||||
// Get smart coupon type string.
|
||||
if ( 'smart_coupon' === $discount_type && 'yes' === $is_gift ) {
|
||||
$smart_coupon_type = __( 'Gift Card', 'woocommerce-smart-coupons' );
|
||||
} else {
|
||||
$smart_coupon_type = __( 'Store Credit', 'woocommerce-smart-coupons' );
|
||||
}
|
||||
|
||||
if ( ! empty( $store_credit_label['singular'] ) ) {
|
||||
$smart_coupon_type = ucwords( $store_credit_label['singular'] );
|
||||
}
|
||||
|
||||
$amount = $coupon['amount'];
|
||||
$coupon_code = $coupon['code'];
|
||||
|
||||
// Get coupon types.
|
||||
$all_discount_types = wc_get_coupon_types();
|
||||
|
||||
$_coupon = new WC_Coupon( $coupon_code );
|
||||
|
||||
if ( $woocommerce_smart_coupon->is_wc_gte_30() ) {
|
||||
$_coupon_id = ( is_object( $_coupon ) && is_callable( array( $_coupon, 'get_id' ) ) ) ? $_coupon->get_id() : 0;
|
||||
$_is_free_shipping = ( $_coupon->get_free_shipping() ) ? 'yes' : 'no';
|
||||
$_discount_type = $_coupon->get_discount_type();
|
||||
$_product_ids = $_coupon->get_product_ids();
|
||||
$_excluded_product_ids = $_coupon->get_excluded_product_ids();
|
||||
$_product_categories = $_coupon->get_product_categories();
|
||||
$_excluded_product_categories = $_coupon->get_excluded_product_categories();
|
||||
} else {
|
||||
$_coupon_id = ( ! empty( $_coupon->id ) ) ? $_coupon->id : 0;
|
||||
$_is_free_shipping = ( ! empty( $_coupon->free_shipping ) ) ? $_coupon->free_shipping : '';
|
||||
$_discount_type = ( ! empty( $_coupon->discount_type ) ) ? $_coupon->discount_type : '';
|
||||
$_product_ids = ( ! empty( $_coupon->product_ids ) ) ? $_coupon->product_ids : array();
|
||||
$_excluded_product_ids = ( ! empty( $_coupon->exclude_product_ids ) ) ? $_coupon->exclude_product_ids : array();
|
||||
$_product_categories = ( ! empty( $_coupon->product_categories ) ) ? $_coupon->product_categories : array();
|
||||
$_excluded_product_categories = ( ! empty( $_coupon->exclude_product_categories ) ) ? $_coupon->exclude_product_categories : array();
|
||||
}
|
||||
|
||||
if ( false === stripos( $discount_type, 'percent' ) ) {
|
||||
$amount = $woocommerce_smart_coupon->read_price( $amount, true, $order );
|
||||
}
|
||||
|
||||
switch ( $discount_type ) {
|
||||
|
||||
case 'smart_coupon':
|
||||
/* translators: %s coupon amount */
|
||||
$coupon_value = sprintf( __( 'worth %s ', 'woocommerce-smart-coupons' ), wc_price( $amount, $wc_price_args ) );
|
||||
break;
|
||||
|
||||
case 'fixed_cart':
|
||||
/* translators: %s: coupon amount */
|
||||
$coupon_value = sprintf( __( 'worth %s (for entire purchase) ', 'woocommerce-smart-coupons' ), wc_price( $amount, $wc_price_args ) );
|
||||
break;
|
||||
|
||||
case 'fixed_product':
|
||||
if ( ! empty( $_product_ids ) || ! empty( $_excluded_product_ids ) || ! empty( $_product_categories ) || ! empty( $_excluded_product_categories ) ) {
|
||||
$_discount_for_text = __( 'for some products', 'woocommerce-smart-coupons' );
|
||||
} else {
|
||||
$_discount_for_text = __( 'for all products', 'woocommerce-smart-coupons' );
|
||||
}
|
||||
|
||||
/* translators: 1: coupon amount 2: discount for text */
|
||||
$coupon_value = sprintf( __( 'worth %1$s (%2$s) ', 'woocommerce-smart-coupons' ), wc_price( $amount, $wc_price_args ), $_discount_for_text );
|
||||
break;
|
||||
|
||||
case 'percent_product':
|
||||
if ( ! empty( $_product_ids ) || ! empty( $_excluded_product_ids ) || ! empty( $_product_categories ) || ! empty( $_excluded_product_categories ) ) {
|
||||
$_discount_for_text = __( 'for some products', 'woocommerce-smart-coupons' );
|
||||
} else {
|
||||
$_discount_for_text = __( 'for all products', 'woocommerce-smart-coupons' );
|
||||
}
|
||||
|
||||
/* translators: 1: coupon amount 2: discount for text */
|
||||
$coupon_value = sprintf( __( 'worth %1$s%% (%2$s) ', 'woocommerce-smart-coupons' ), $amount, $_discount_for_text );
|
||||
break;
|
||||
|
||||
case 'percent':
|
||||
if ( ! empty( $_product_ids ) || ! empty( $_excluded_product_ids ) || ! empty( $_product_categories ) || ! empty( $_excluded_product_categories ) ) {
|
||||
$_discount_for_text = __( 'for some products', 'woocommerce-smart-coupons' );
|
||||
} else {
|
||||
$_discount_for_text = __( 'for entire purchase', 'woocommerce-smart-coupons' );
|
||||
}
|
||||
|
||||
$max_discount_text = '';
|
||||
$max_discount = $woocommerce_smart_coupon->get_post_meta( $_coupon_id, 'wc_sc_max_discount', true, true, $order );
|
||||
if ( ! empty( $max_discount ) && is_numeric( $max_discount ) ) {
|
||||
/* translators: %s: Maximum coupon discount amount */
|
||||
$max_discount_text = sprintf( __( ' upto %s', 'woocommerce-smart-coupons' ), wc_price( $max_discount, $wc_price_args ) );
|
||||
}
|
||||
|
||||
/* translators: 1: coupon amount 2: max discount text 3: discount for text */
|
||||
$coupon_value = sprintf( __( 'worth %1$s%% %2$s (%3$s) ', 'woocommerce-smart-coupons' ), $amount, $max_discount_text, $_discount_for_text );
|
||||
break;
|
||||
|
||||
default:
|
||||
$default_coupon_type = ( ! empty( $all_discount_types[ $discount_type ] ) ) ? $all_discount_types[ $discount_type ] : ucwords( str_replace( array( '_', '-' ), ' ', $discount_type ) );
|
||||
$coupon_type = apply_filters( 'wc_sc_coupon_type', $default_coupon_type, $_coupon, $all_discount_types );
|
||||
$coupon_amount = apply_filters( 'wc_sc_coupon_amount', $amount, $_coupon );
|
||||
|
||||
/* translators: 1: coupon type 2: coupon amount */
|
||||
$coupon_value = sprintf( __( '%1$s coupon of %2$s', 'woocommerce-smart-coupons' ), $coupon_type, $coupon_amount );
|
||||
$coupon_value = apply_filters( 'wc_sc_email_heading', $coupon_value, $_coupon );
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
if ( 'yes' === $_is_free_shipping && in_array( $_discount_type, array( 'fixed_cart', 'fixed_product', 'percent_product', 'percent' ), true ) ) {
|
||||
/* translators: 1: email heading 2: suffix */
|
||||
$coupon_value = sprintf( __( '%1$s Free Shipping%2$s', 'woocommerce-smart-coupons' ), ( ( ! empty( $amount ) ) ? $coupon_value . __( '&', 'woocommerce-smart-coupons' ) : __( 'You have received a', 'woocommerce-smart-coupons' ) ), ( ( empty( $amount ) ) ? __( ' coupon', 'woocommerce-smart-coupons' ) : '' ) );
|
||||
}
|
||||
|
||||
return wp_strip_all_tags( $coupon_value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to get coupon type for current coupon being sent.
|
||||
*
|
||||
* @return string $coupon_type Coupon type.
|
||||
*/
|
||||
public function get_coupon_type() {
|
||||
|
||||
global $store_credit_label;
|
||||
|
||||
$discount_type = isset( $this->email_args['discount_type'] ) ? $this->email_args['discount_type'] : '';
|
||||
$is_gift = isset( $this->email_args['is_gift'] ) ? $this->email_args['is_gift'] : '';
|
||||
|
||||
if ( 'smart_coupon' === $discount_type && 'yes' === $is_gift ) {
|
||||
$smart_coupon_type = __( 'Gift Card', 'woocommerce-smart-coupons' );
|
||||
} else {
|
||||
$smart_coupon_type = __( 'Store Credit', 'woocommerce-smart-coupons' );
|
||||
}
|
||||
|
||||
if ( ! empty( $store_credit_label['singular'] ) ) {
|
||||
$smart_coupon_type = ucwords( $store_credit_label['singular'] );
|
||||
}
|
||||
|
||||
$coupon_type = ( 'smart_coupon' === $discount_type && ! empty( $smart_coupon_type ) ) ? $smart_coupon_type : __( 'coupon', 'woocommerce-smart-coupons' );
|
||||
|
||||
return $coupon_type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to update SC admin email settings when WC email settings get updated
|
||||
*/
|
||||
public function process_admin_options() {
|
||||
// Save regular options.
|
||||
parent::process_admin_options();
|
||||
|
||||
$is_email_enabled = $this->get_field_value( 'enabled', $this->form_fields['enabled'] );
|
||||
|
||||
if ( ! empty( $is_email_enabled ) ) {
|
||||
update_option( 'smart_coupons_is_send_email', $is_email_enabled, 'no' );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,149 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Main class for Smart Coupons Email
|
||||
*
|
||||
* @author StoreApps
|
||||
* @since 4.4.1
|
||||
* @version 1.2.1
|
||||
*
|
||||
* @package woocommerce-smart-coupons/includes/emails/
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'WC_SC_Email' ) ) {
|
||||
/**
|
||||
* The Smart Coupons Email class
|
||||
*
|
||||
* @extends \WC_Email
|
||||
*/
|
||||
class WC_SC_Email extends WC_Email {
|
||||
|
||||
/**
|
||||
* Email args defaults
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $email_args = array(
|
||||
'email' => '',
|
||||
'coupon' => array(),
|
||||
'discount_type' => 'smart_coupon',
|
||||
'smart_coupon_type' => '',
|
||||
'receiver_name' => '',
|
||||
'message_from_sender' => '',
|
||||
'gift_certificate_sender_name' => '',
|
||||
'gift_certificate_sender_email' => '',
|
||||
'from' => '',
|
||||
'sender' => '',
|
||||
'is_gift' => false,
|
||||
);
|
||||
|
||||
/**
|
||||
* Get shop page url
|
||||
*
|
||||
* @return string $url Shop page url
|
||||
*/
|
||||
public function get_url() {
|
||||
|
||||
global $woocommerce_smart_coupon;
|
||||
|
||||
if ( $woocommerce_smart_coupon->is_wc_gte_30() ) {
|
||||
$page_id = wc_get_page_id( 'shop' );
|
||||
} else {
|
||||
$page_id = woocommerce_get_page_id( 'shop' );
|
||||
}
|
||||
|
||||
$url = ( get_option( 'permalink_structure' ) ) ? get_permalink( $page_id ) : get_post_type_archive_link( 'product' );
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to get sender name.
|
||||
*
|
||||
* @return string $sender_name Sender name.
|
||||
*/
|
||||
public function get_sender_name() {
|
||||
|
||||
if ( isset( $this->email_args['gift_certificate_sender_name'] ) && ! empty( $this->email_args['gift_certificate_sender_name'] ) ) {
|
||||
$sender_name = $this->email_args['gift_certificate_sender_name'];
|
||||
} else {
|
||||
$sender_name = is_callable( array( $this, 'get_blogname' ) ) ? $this->get_blogname() : '';
|
||||
}
|
||||
|
||||
return $sender_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to get sender email.
|
||||
*
|
||||
* @return string $sender_email Sender email.
|
||||
*/
|
||||
public function get_sender_email() {
|
||||
|
||||
$sender_email = isset( $this->email_args['gift_certificate_sender_email'] ) ? $this->email_args['gift_certificate_sender_email'] : '';
|
||||
|
||||
return $sender_email;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize Settings Form Fields
|
||||
*/
|
||||
public function init_form_fields() {
|
||||
|
||||
/* translators: %s: list of placeholders */
|
||||
$placeholder_text = sprintf( __( 'Available placeholders: %s', 'woocommerce-smart-coupons' ), '<code>' . implode( '</code>, <code>', array_keys( $this->placeholders ) ) . '</code>' );
|
||||
|
||||
$this->form_fields = array(
|
||||
'enabled' => array(
|
||||
'title' => __( 'Enable/Disable', 'woocommerce-smart-coupons' ),
|
||||
'type' => 'checkbox',
|
||||
'label' => __( 'Enable this email notification', 'woocommerce-smart-coupons' ),
|
||||
'default' => 'yes',
|
||||
),
|
||||
'email_type' => array(
|
||||
'title' => __( 'Email type', 'woocommerce-smart-coupons' ),
|
||||
'type' => 'select',
|
||||
'description' => __( 'Choose which format of email to send.', 'woocommerce-smart-coupons' ),
|
||||
'default' => 'html',
|
||||
'class' => 'email_type wc-enhanced-select',
|
||||
'options' => $this->get_email_type_options(),
|
||||
'desc_tip' => true,
|
||||
),
|
||||
'subject' => array(
|
||||
'title' => __( 'Subject', 'woocommerce-smart-coupons' ),
|
||||
'type' => 'text',
|
||||
'desc_tip' => true,
|
||||
'description' => $placeholder_text,
|
||||
'placeholder' => $this->get_default_subject(),
|
||||
'default' => '',
|
||||
),
|
||||
'heading' => array(
|
||||
'title' => __( 'Email heading', 'woocommerce-smart-coupons' ),
|
||||
'type' => 'text',
|
||||
'desc_tip' => true,
|
||||
'description' => $placeholder_text,
|
||||
'placeholder' => $this->get_default_heading(),
|
||||
'default' => '',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to update SC admin email settings when WC email settings get updated
|
||||
*/
|
||||
public function process_admin_options() {
|
||||
// Save regular options.
|
||||
parent::process_admin_options();
|
||||
|
||||
$is_email_enabled = $this->get_field_value( 'enabled', $this->form_fields['enabled'] );
|
||||
|
||||
if ( ! empty( $is_email_enabled ) ) {
|
||||
update_option( 'smart_coupons_is_send_email', $is_email_enabled, 'no' );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user