| 1 |
<?php |
| 2 |
namespace Emailkit\Admin\Emails; |
| 3 |
|
| 4 |
defined( "ABSPATH") || exit; |
| 5 |
|
| 6 |
class EmailLists { |
| 7 |
const NEW_ORDER = "new_order"; |
| 8 |
const CANCELLED_ORDER = "cancelled_order"; |
| 9 |
const FAILED_ORDER = "failed_order"; |
| 10 |
const ORDER_ON_HOLD = "customer_on_hold_order"; |
| 11 |
const PROCESSING_ORDER = "customer_processing_order"; |
| 12 |
const COMPLETED_ORDER = "customer_completed_order"; |
| 13 |
const REFUNDED_ORDER = "customer_refunded_order"; |
| 14 |
const LOW_STOCK = "low_stock"; |
| 15 |
const NO_STOCK = "no_stock"; |
| 16 |
const BACK_ORDER = "back_order"; |
| 17 |
const CUSTOMER_INVOICE_OR_ORDER_DETAILS = "customer_invoice"; |
| 18 |
// const ORDER_DETAILS = "Order Details"; |
| 19 |
const CUSTOMER_NOTE = "customer_note"; |
| 20 |
const RESET_PASSWORD = "customer_reset_password"; |
| 21 |
const NEW_ACCOUNT = "customer_new_account"; |
| 22 |
const WP_NEW_REGISTER = "new_register"; |
| 23 |
const WP_RESET_PASSWORD = "reset_account"; |
| 24 |
const PARTIAL_REFUND = "partial_refund"; |
| 25 |
|
| 26 |
|
| 27 |
/** |
| 28 |
* Get woocommerce template names |
| 29 |
* @return array |
| 30 |
*/ |
| 31 |
public static function woocommerce_email($template_type = '') { |
| 32 |
$list = [ |
| 33 |
'Select Template' => esc_html__('Select Template', 'emailkit'), |
| 34 |
self::NEW_ORDER => esc_html__('New Order', 'emailkit'), |
| 35 |
self::CANCELLED_ORDER => esc_html__('Cancelled order', 'emailkit'), |
| 36 |
self::FAILED_ORDER => esc_html__('Failed Order', 'emailkit'), |
| 37 |
self::ORDER_ON_HOLD => esc_html__('Order On Hold', 'emailkit'), |
| 38 |
self::PROCESSING_ORDER => esc_html__('Processing Order', 'emailkit'), |
| 39 |
self::COMPLETED_ORDER => esc_html__('Completed Order', 'emailkit'), |
| 40 |
self::LOW_STOCK => esc_html__('Low Stock', 'emailkit'), |
| 41 |
self::NO_STOCK => esc_html__('No Stock', 'emailkit'), |
| 42 |
self::BACK_ORDER => esc_html__('Back Order', 'emailkit'), |
| 43 |
self::REFUNDED_ORDER => esc_html__('Refunded Order', 'emailkit'), |
| 44 |
self::PARTIAL_REFUND => esc_html__('Partial Refund', 'emailkit'), |
| 45 |
self::CUSTOMER_INVOICE_OR_ORDER_DETAILS => esc_html__('Customer Invoice ', 'emailkit'), |
| 46 |
self::CUSTOMER_NOTE => esc_html__('Customer Note', 'emailkit'), |
| 47 |
self::NEW_ACCOUNT => esc_html__('New Account', 'emailkit'), |
| 48 |
self::RESET_PASSWORD => esc_html__('Reset Password', 'emailkit'), |
| 49 |
]; |
| 50 |
|
| 51 |
if($template_type){ |
| 52 |
return isset($list[$template_type]) ? $list[$template_type] : ''; |
| 53 |
} |
| 54 |
|
| 55 |
return $list; |
| 56 |
} |
| 57 |
|
| 58 |
/** |
| 59 |
* Get wordpress template names |
| 60 |
* @return array |
| 61 |
*/ |
| 62 |
public static function wordpress_email($template_type = '') { |
| 63 |
$list = [ |
| 64 |
'Select Template' => esc_html__('Select Template', 'emailkit'), |
| 65 |
self::WP_NEW_REGISTER => esc_html__('New Register', 'emailkit'), |
| 66 |
self::WP_RESET_PASSWORD => esc_html__('Reset Account', 'emailkit'), |
| 67 |
]; |
| 68 |
|
| 69 |
if ($template_type) { |
| 70 |
return isset($list[$template_type]) ? $list[$template_type] : ''; |
| 71 |
} |
| 72 |
|
| 73 |
return $list; |
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
/** |
| 78 |
* Get saved templates from database |
| 79 |
* @return array |
| 80 |
*/ |
| 81 |
public static function saved_templates() : array { |
| 82 |
|
| 83 |
$emailkit_saved_templates = []; |
| 84 |
|
| 85 |
$templates = get_posts([ |
| 86 |
'post_type' => 'emailkit-template', |
| 87 |
'numberposts' => -1, |
| 88 |
]); |
| 89 |
|
| 90 |
|
| 91 |
foreach ( $templates as $template ) { |
| 92 |
|
| 93 |
setup_postdata( $template ); |
| 94 |
|
| 95 |
$template_id = get_post_meta( $template->ID, 'emailkit_template_id', true ); //get the id of main template to fetch types and etc |
| 96 |
|
| 97 |
$emailkit_saved_templates[] = array( |
| 98 |
'title' => $template->post_title, |
| 99 |
'id' => $template->ID, |
| 100 |
'template_id' => $template_id, |
| 101 |
'email_type' => get_post_meta( $template_id, 'emailkit_email_type', true ), |
| 102 |
'template_type' => get_post_meta( $template_id, 'emailkit_template_type', true ), |
| 103 |
'template_status' => get_post_meta( $template_id, 'emailkit_template_status', true ), |
| 104 |
); |
| 105 |
|
| 106 |
} |
| 107 |
|
| 108 |
wp_reset_postdata(); |
| 109 |
|
| 110 |
|
| 111 |
return $emailkit_saved_templates; |
| 112 |
} |
| 113 |
|
| 114 |
|
| 115 |
} |