File: /home/royaltuning/www/public/wp-content/plugins/vp-woo-review-reminder/class-email.php
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
if ( ! class_exists( 'VP_Woo_Review_Reminder_Email', false ) ) :
class VP_Woo_Review_Reminder_Email extends WC_Email {
public $product;
public $website;
public function __construct() {
$this->id = 'vp_woo_review_reminder';
$this->customer_email = true;
$this->title = __( 'Review Reminder', 'vp-woo-review-reminder' );
$this->description = __( 'Send an e-mail reminding the customer to leave a review about the most recent purchase.', 'vp-woo-review-reminder' );
$this->template_html = 'emails/review-reminder.php';
$this->template_plain = 'emails/plain/review-reminder.php';
$this->template_base = plugin_dir_path( __FILE__ ) . 'templates/';
$this->website = false;
$this->placeholders = array(
'{order_date}' => '',
'{order_number}' => '',
'{product_name}' => '',
'{product_image}' => '',
'{customer_name}' => ''
);
// Call parent constructor.
parent::__construct();
}
public function get_default_subject() {
return __( 'We’d love your feedback', 'vp-woo-review-reminder' );
}
public function get_default_heading( ) {
return __( 'What do you think about your recent {site_title} purchase?', 'vp-woo-review-reminder' );
}
public function trigger( $order_id, $order, $product = false ) {
$this->setup_locale();
if ( $order_id && ! is_a( $order, 'WC_Order' ) ) {
$order = wc_get_order( $order_id );
}
if ( is_a( $order, 'WC_Order' ) && $product ) {
$this->object = $order;
$this->product = $product;
$this->recipient = $this->object->get_billing_email();
$this->placeholders['{order_date}'] = wc_format_datetime( $this->object->get_date_created() );
$this->placeholders['{order_number}'] = $this->object->get_order_number();
$this->placeholders['{customer_name}'] = $this->object->get_billing_first_name();
$this->placeholders['{product_name}'] = $product->get_name();
if($product->get_image_id()) {
$this->placeholders['{product_image}'] = '<p style="text-align:center">'.$product->get_image('large', array('loading' => false)).'</p>';
}
}
if ( $this->get_recipient() && !$this->website ) {
$this->send( $this->get_recipient(), $this->get_subject(), $this->get_content_html(), $this->get_headers(), $this->get_attachments() );
}
$this->restore_locale();
}
public function get_content_html() {
return wc_get_template_html(
$this->template_html,
array(
'order' => $this->object,
'email_heading' => $this->get_heading(),
'sent_to_admin' => false,
'plain_text' => false,
'email' => $this,
'content' => $this->get_body(),
'product' => $this->product
),
'',
$this->template_base
);
}
public function get_default_content() {
return __('Hello {customer_name}! You’ve recently bought {product_name} at our store, what do you think about it? {product_image}', 'vp-woo-review-reminder');
}
public function get_body() {
return $this->format_string( $this->get_option( 'content', $this->get_default_content() ) );
}
public function init_form_fields() {
/* translators: %s: list of placeholders */
$placeholder_text = sprintf( __( 'Available placeholders: %s', 'vp-woo-review-reminder' ), '<code>' . esc_html( implode( '</code>, <code>', array_keys( $this->placeholders ) ) ) . '</code>' );
$this->form_fields = array(
'enabled' => array(
'title' => __( 'Enable/Disable', 'vp-woo-review-reminder' ),
'type' => 'checkbox',
'label' => __( 'Enable this email notification', 'vp-woo-review-reminder' ),
'default' => 'no',
),
'subject' => array(
'title' => __( 'Subject', 'vp-woo-review-reminder' ),
'type' => 'text',
'desc_tip' => true,
'description' => $placeholder_text,
'placeholder' => $this->get_default_subject(),
'default' => '',
),
'heading' => array(
'title' => __( 'Email heading', 'vp-woo-review-reminder' ),
'type' => 'text',
'desc_tip' => true,
'description' => $placeholder_text,
'placeholder' => $this->get_default_heading(),
'default' => '',
),
'content' => array(
'title' => __( 'Content', 'vp-woo-review-reminder' ),
'description' => __( 'Text to appear as the main email content.', 'vp-woo-review-reminder' ) . ' ' . $placeholder_text,
'css' => 'width:400px; height: 75px;',
'type' => 'textarea',
'default' => $this->get_default_content(),
'desc_tip' => true,
),
'delay' => array(
'title' => __( 'Sending delay(days)', 'vp-woo-review-reminder' ),
'type' => 'number',
'desc_tip' => true,
'description' => __('The e-mail will be scheduled to be sent after the order status changed to completed in X days.', 'vp-woo-review-reminder' ),
'default' => 5,
),
'email_type' => array(
'title' => __( 'Email type', 'vp-woo-review-reminder' ),
'type' => 'select',
'description' => __( 'Choose which format of email to send.', 'vp-woo-review-reminder' ),
'default' => 'html',
'class' => 'email_type wc-enhanced-select',
'options' => $this->get_email_type_options(),
'desc_tip' => true,
),
);
}
}
endif;