| @@ -1,220 +1,232 @@ | ||
| 1 | -<?php | |
| 2 | - | |
| 3 | -namespace EmailKit\Admin\Api; | |
| 4 | - | |
| 5 | -defined('ABSPATH') || exit; | |
| 6 | - | |
| 7 | -class ShortCodeData { | |
| 8 | - /** | |
| 9 | - * @var string | |
| 10 | - */ | |
| 11 | - public $prefix = ''; | |
| 12 | - /** | |
| 13 | - * @var string | |
| 14 | - */ | |
| 15 | - public $param = ''; | |
| 16 | - /** | |
| 17 | - * @var mixed | |
| 18 | - */ | |
| 19 | - public $request = null; | |
| 20 | - | |
| 21 | - public function __construct() { | |
| 22 | - add_action('rest_api_init', function () { | |
| 23 | - register_rest_route('emailkit/v1', 'order-data', [ | |
| 24 | - 'methods' => \WP_REST_Server::ALLMETHODS, | |
| 25 | - 'callback' => [$this, 'get_order_data'], | |
| 26 | - 'permission_callback' => '__return_true' | |
| 27 | - ]); | |
| 28 | - }); | |
| 29 | - } | |
| 30 | - | |
| 31 | - /** | |
| 32 | - * @param $request | |
| 33 | - */ | |
| 34 | - public function get_order_data($request) { | |
| 35 | - if(!wp_verify_nonce($request->get_header('X-WP-Nonce'), 'wp_rest')) { | |
| 36 | - return [ | |
| 37 | - 'status' => 'fail', | |
| 38 | - 'message' => [ __( 'Nonce mismatch.', 'emailkit' )] | |
| 39 | - ]; | |
| 40 | - } | |
| 41 | - | |
| 42 | - if(!is_user_logged_in() || !current_user_can('publish_posts')) { | |
| 43 | - return [ | |
| 44 | - 'status' => 'fail', | |
| 45 | - 'message' => ['Access denied.'] | |
| 46 | - ]; | |
| 47 | - } | |
| 48 | - | |
| 49 | - | |
| 50 | - | |
| 51 | - $short_codes = []; | |
| 52 | - $current_user = wp_get_current_user(); | |
| 53 | - $user_name = $current_user->user_login; | |
| 54 | - $display_name = $current_user->display_name; | |
| 55 | - $user_email = $current_user->user_email; | |
| 56 | - $app_name = get_bloginfo('name'); | |
| 57 | - | |
| 58 | - // Site shortcodes | |
| 59 | - $short_codes[] = ['key' => 'site_name', 'value' => get_bloginfo( 'name' )]; | |
| 60 | - $short_codes[] = ['key' => 'site_url', 'value' => get_bloginfo( 'url')]; | |
| 61 | - $short_codes[] = ['key' => 'user_name', 'value' => $user_name]; | |
| 62 | - $short_codes[] = ['key' => 'display_name', 'value' => $display_name]; | |
| 63 | - $short_codes[] = ['key' => 'wp_user_email', 'value' => $user_email]; | |
| 64 | - $short_codes[] = ['key' => 'app_name', 'value' => $app_name]; | |
| 65 | - $short_codes[] = ['key' => 'user_login', 'value' => $user_name]; | |
| 66 | - | |
| 67 | - | |
| 68 | - if(is_plugin_active('woocommerce/woocommerce.php')) { | |
| 69 | - | |
| 70 | - | |
| 71 | - $orders = wc_get_orders([ | |
| 72 | - 'limit' => 1, | |
| 73 | - 'orderby' => 'date', | |
| 74 | - 'order' => 'DESC', | |
| 75 | - 'status' => array_keys( wc_get_order_statuses()), | |
| 76 | - ]); | |
| 77 | - | |
| 78 | - if(!empty($orders)) { | |
| 79 | - | |
| 80 | - $order = $orders[0]; | |
| 81 | - | |
| 82 | - | |
| 83 | - foreach($order->get_items() as $item_id => $item) { | |
| 84 | - $product = $item->get_product(); | |
| 85 | - $short_codes[] = ['key' => 'product_name', 'value' => $product->get_name()]; | |
| 86 | - $short_codes[] = ['key' => 'product_price', 'value' => wc_price($product->get_price())]; | |
| 87 | - } | |
| 88 | - | |
| 89 | - $customer = $order->get_user(); | |
| 90 | - | |
| 91 | - // Include customer name and email in the order data | |
| 92 | - if ($customer) { | |
| 93 | - $short_codes[] = ['key' => 'user_login', 'value' => $customer->display_name]; | |
| 94 | - $short_codes[] = ['key' => 'user_email', 'value' => $customer->user_email]; | |
| 95 | - } | |
| 96 | - // Order shortcodes | |
| 97 | - $short_codes[] = ['key' => 'product_name', 'value' => 'T-Shirt with logo']; | |
| 98 | - $short_codes[] = ['key' => 'quantity', 'value' => method_exists($order, 'get_item_count') ? $order->get_item_count() : '2']; | |
| 99 | - $short_codes[] = ['key' => 'order_id', 'value' => method_exists($order, 'get_id') ? $order->get_id() : '1']; | |
| 100 | - $short_codes[] = ['key' => 'order_status', 'value' => method_exists($order, 'get_status') ? $order->get_status() : 'pending']; | |
| 101 | - $short_codes[] = ['key' => 'order_number', 'value' => method_exists($order, 'get_order_number') ? $order->get_order_number() : '1']; | |
| 102 | - $short_codes[] = ['key' => 'order_currency', 'value' => method_exists($order, 'get_currency') ? $order->get_currency() : '$']; | |
| 103 | - $short_codes[] = ['key' => 'order_subtotal', 'value' => method_exists($order, 'get_subtotal') ? wc_price($order->get_subtotal()) : '$0.00']; | |
| 104 | - $short_codes[] = ['key' => 'order_date', 'value' => method_exists($order, 'get_date_created') ? gmdate('Y-m-d H:i:s', strtotime($order->get_date_created()->format('Y-m-d H:i:s'))) : '2020-01-01 00:00:00']; | |
| 105 | - $short_codes[] = ['key' => 'payment_method', 'value' => method_exists($order, 'get_payment_method_title') ? $order->get_payment_method_title() : 'Cash On Delivery']; | |
| 106 | - $short_codes[] = ['key' => 'total', 'value' => method_exists($order, 'get_total') ? wc_price($order->get_total(), 2) : '$0.00']; | |
| 107 | - $short_codes[] = ['key' => 'customer_note', 'value' => method_exists($order, 'get_customer_note') ? ( !empty($order->get_customer_note()) ? $order->get_customer_note() : __('Happy to order', 'emailkit') ) : __('Happy to order', 'emailkit')]; | |
| 108 | - // Billing shortcodes | |
| 109 | - $short_codes[] = ['key' => 'billing_name', 'value' => method_exists($order, 'get_formatted_billing_full_name') ? $order->get_formatted_billing_full_name() : 'Jon Doe']; | |
| 110 | - $short_codes[] = ['key' => 'billing_first_name', 'value' => method_exists($order, 'get_billing_first_name') ? $order->get_billing_first_name() : 'Jon']; | |
| 111 | - $short_codes[] = ['key' => 'billing_last_name', 'value' => method_exists($order, 'get_billing_last_name') ? $order->get_billing_last_name() : 'Doe']; | |
| 112 | - $short_codes[] = ['key' => 'billing_email', 'value' => method_exists($order, 'get_billing_email') ? $order->get_billing_email() : 'jondoe@example.com']; | |
| 113 | - $short_codes[] = ['key' => 'billing_phone', 'value' => method_exists($order, 'get_billing_phone') ? $order->get_billing_phone() : '3456789']; | |
| 114 | - $short_codes[] = ['key' => 'billing_company', 'value' => method_exists($order, 'get_billing_company') ? $order->get_billing_company() : 'xyz.com']; | |
| 115 | - $short_codes[] = ['key' => 'billing_address_1', 'value' => method_exists($order, 'get_billing_address_1') ? $order->get_billing_address_1() : 'USA']; | |
| 116 | - $short_codes[] = ['key' => 'billing_address_2', 'value' => method_exists($order, 'get_billing_address_2') ? $order->get_billing_address_2() : 'USA']; | |
| 117 | - $short_codes[] = ['key' => 'billing_city', 'value' => method_exists($order, 'get_billing_city') ? $order->get_billing_city() : 'USA']; | |
| 118 | - $short_codes[] = ['key' => 'billing_country', 'value' => method_exists($order, 'get_billing_country') ? $order->get_billing_country() : 'America']; | |
| 119 | - $short_codes[] = ['key' => 'billing_postcode', 'value' => method_exists($order, 'get_billing_postcode') ? $order->get_billing_postcode() : '123456']; | |
| 120 | - $short_codes[] = ['key' => 'billing_state', 'value' => method_exists($order, 'get_billing_state') ? $order->get_billing_state() : 'NORTH CAROLINA']; | |
| 121 | - | |
| 122 | - // Shipping shortcodes | |
| 123 | - $short_codes[] = ['key' => 'shipping_first_name', 'value' => method_exists($order, 'get_shipping_first_name') ? $order->get_shipping_first_name() : 'Jon']; | |
| 124 | - $short_codes[] = ['key' => 'shipping_last_name', 'value' => method_exists($order, 'get_shipping_last_name') ? $order->get_shipping_last_name() : 'Doe']; | |
| 125 | - $short_codes[] = ['key' => 'shipping_total', 'value' => method_exists($order, 'get_shipping_total') ? wc_price($order->get_shipping_total()) : '$0.00']; | |
| 126 | - $short_codes[] = ['key' => 'shipping_tax_total', 'value' => method_exists($order, 'get_shipping_tax') ? wc_format_decimal($order->get_shipping_tax(), 2) : '$0.00']; | |
| 127 | - $short_codes[] = ['key' => 'shipping_company', 'value' => method_exists($order, 'get_shipping_company') ? $order->get_shipping_company() : 'xyz.com']; | |
| 128 | - $short_codes[] = ['key' => 'shipping_address_1', 'value' => method_exists($order, 'get_shipping_address_1') ? $order->get_shipping_address_1() : 'USA']; | |
| 129 | - $short_codes[] = ['key' => 'shipping_address_2', 'value' => method_exists($order, 'get_shipping_address_2') ? $order->get_shipping_address_2() : 'USA']; | |
| 130 | - $short_codes[] = ['key' => 'shipping_method', 'value' => method_exists($order, 'get_shipping_method') ? $order->get_shipping_method() : 'Cash']; | |
| 131 | - $short_codes[] = ['key' => 'shipping_city', 'value' => method_exists($order, 'get_shipping_city') ? $order->get_shipping_city() : 'America']; | |
| 132 | - $short_codes[] = ['key' => 'shipping_state', 'value' => method_exists($order, 'get_shipping_state') ? $order->get_shipping_state() : 'North Carolina']; | |
| 133 | - $short_codes[] = ['key' => 'shipping_postcode', 'value' => method_exists($order, 'get_shipping_postcode') ? $order->get_shipping_postcode() : '123456']; | |
| 134 | - $short_codes[] = ['key' => 'shipping_country', 'value' => method_exists($order, 'get_shipping_country') ? $order->get_shipping_country() : 'America']; | |
| 135 | - $short_codes[] = ['key' => 'shipping_phone', 'value' => method_exists($order, 'get_shipping_phone') ? $order->get_shipping_phone() : '3456789']; | |
| 136 | - | |
| 137 | - | |
| 138 | - | |
| 139 | - return [ | |
| 140 | - 'status' => 'success', | |
| 141 | - 'data' => $short_codes, | |
| 142 | - 'message'=> esc_html__( 'WooCommerce order data retrieved successfully.', 'emailkit') | |
| 143 | - ]; | |
| 144 | - } | |
| 145 | - else { | |
| 146 | - | |
| 147 | - return $this->get_demo_data(); | |
| 148 | - } | |
| 149 | - | |
| 150 | - } | |
| 151 | - return $this->get_demo_data(); | |
| 152 | - } | |
| 153 | - | |
| 154 | - public function get_demo_data() { | |
| 155 | - | |
| 156 | - $site_url = get_bloginfo('url'); | |
| 157 | - $current_user = wp_get_current_user(); | |
| 158 | - $user_name = $current_user->user_login; | |
| 159 | - $display_name = $current_user->display_name; | |
| 160 | - $user_email = $current_user->user_email; | |
| 161 | - $app_name = get_bloginfo('name'); | |
| 162 | - | |
| 163 | - $demo_data = [ | |
| 164 | - ['key' => 'order_id', 'value' => '1'], | |
| 165 | - ['key' => 'order_number', 'value' => '1'], | |
| 166 | - ['key' => 'order_status', 'value' => 'pending'], | |
| 167 | - ['key' => 'billing_name', 'value' => 'Jon Doe'], | |
| 168 | - ['key' => 'quantity', 'value' => '2'], | |
| 169 | - ['key' => 'order_currency', 'value' => '$'], | |
| 170 | - ['key' => 'billing_phone', 'value' => '3456789'], | |
| 171 | - ['key' => 'shipping_total', 'value' => '$0.00'], | |
| 172 | - ['key' => 'order_subtotal', 'value' => '$0.00'], | |
| 173 | - ['key' => 'shipping_tax_total', 'value' => '$0.00'], | |
| 174 | - ['key' => 'order_date', 'value' => '2020-01-01 00:00:00'], | |
| 175 | - ['key' => 'shipping_method', 'value' => 'Cash'], | |
| 176 | - ['key' => 'payment_method', 'value' => 'Cash On Delivery'], | |
| 177 | - ['key' => 'total', 'value' => '$0.00'], | |
| 178 | - ['key' => 'billing_first_name', 'value' => 'Jon'], | |
| 179 | - ['key' => 'billing_last_name', 'value' => 'Doe'], | |
| 180 | - ['key' => 'billing_company', 'value' => 'xyz.com'], | |
| 181 | - ['key' => 'billing_address_1', 'value' => 'USA'], | |
| 182 | - ['key' => 'billing_address_2', 'value' => 'USA'], | |
| 183 | - ['key' => 'billing_city', 'value' => 'USA'], | |
| 184 | - ['key' => 'billing_state', 'value' => 'NORTH CAROLINA'], | |
| 185 | - ['key' => 'billing_postcode', 'value' => '123456'], | |
| 186 | - ['key' => 'billing_country', 'value' => 'America'], | |
| 187 | - ['key' => 'billing_email', 'value' => 'jondoe@example.com'], | |
| 188 | - ['key' => 'shipping_first_name', 'value' => 'Jon'], | |
| 189 | - ['key' => 'shipping_last_name', 'value' => 'Doe'], | |
| 190 | - ['key' => 'shipping_company', 'value' => 'xyz.com'], | |
| 191 | - ['key' => 'shipping_address_1', 'value' => 'USA'], | |
| 192 | - ['key' => 'shipping_address_2', 'value' => 'USA'], | |
| 193 | - ['key' => 'shipping_city', 'value' => 'America'], | |
| 194 | - ['key' => 'shipping_state', 'value' => 'North Carolina'], | |
| 195 | - ['key' => 'shipping_postcode', 'value' => '123456'], | |
| 196 | - ['key' => 'shipping_country', 'value' => 'America'], | |
| 197 | - ['key' => 'shipping_phone', 'value' => '3456789'], | |
| 198 | - ['key' => 'customer_note', 'value' => 'Happy To order'], | |
| 199 | - ['key' => 'site_name', 'value' => get_bloginfo( 'name' )], | |
| 200 | - ['key' => 'site_url', 'value' => $site_url], | |
| 201 | - ['key' => 'user_name', 'value' => $user_name], | |
| 202 | - ['key' => 'product_name', 'value' => 'T-Shirt with logo'], | |
| 203 | - ['key' => 'admin_email', 'value' => 'admin@site.com'], | |
| 204 | - ['key' => 'user_login', 'value' => 'admin'], | |
| 205 | - ['key' => 'user_email', 'value' => 'jondoe@example.com'], | |
| 206 | - ['key' => 'site_url', 'value' => $site_url], | |
| 207 | - ['key' => 'display_name', 'value' => $display_name], | |
| 208 | - ['key' => 'wp_user_email', 'value' => $user_email], | |
| 209 | - ['key' => 'app_name', 'value' => $app_name], | |
| 210 | - | |
| 211 | - | |
| 212 | - ]; | |
| 213 | - | |
| 214 | - return [ | |
| 215 | - 'status' => 'success', | |
| 216 | - 'data' => $demo_data, | |
| 217 | - 'message' => __( 'No WooCommerce orders found. Returning demo data.', 'emailkit') | |
| 218 | - ]; | |
| 219 | - } | |
| 220 | -} | |
| 1 | +<?php | |
| 2 | + | |
| 3 | +namespace EmailKit\Admin\Api; | |
| 4 | + | |
| 5 | +defined('ABSPATH') || exit; | |
| 6 | + | |
| 7 | +class ShortCodeData { | |
| 8 | + /** | |
| 9 | + * @var string | |
| 10 | + */ | |
| 11 | + public $prefix = ''; | |
| 12 | + /** | |
| 13 | + * @var string | |
| 14 | + */ | |
| 15 | + public $param = ''; | |
| 16 | + /** | |
| 17 | + * @var mixed | |
| 18 | + */ | |
| 19 | + public $request = null; | |
| 20 | + | |
| 21 | + public function __construct() { | |
| 22 | + add_action('rest_api_init', function () { | |
| 23 | + register_rest_route('emailkit/v1', 'order-data', [ | |
| 24 | + 'methods' => \WP_REST_Server::ALLMETHODS, | |
| 25 | + 'callback' => [$this, 'get_order_data'], | |
| 26 | + 'permission_callback' => '__return_true' | |
| 27 | + ]); | |
| 28 | + }); | |
| 29 | + } | |
| 30 | + | |
| 31 | + /** | |
| 32 | + * @param $request | |
| 33 | + */ | |
| 34 | + public function get_order_data($request) { | |
| 35 | + if(!wp_verify_nonce($request->get_header('X-WP-Nonce'), 'wp_rest')) { | |
| 36 | + return [ | |
| 37 | + 'status' => 'fail', | |
| 38 | + 'message' => [ __( 'Nonce mismatch.', 'emailkit' )] | |
| 39 | + ]; | |
| 40 | + } | |
| 41 | + | |
| 42 | + if(!is_user_logged_in() || !current_user_can('manage_options')) { | |
| 43 | + return [ | |
| 44 | + 'status' => 'fail', | |
| 45 | + 'message' => [esc_html__( 'Access denied.', 'emailkit' )] | |
| 46 | + ]; | |
| 47 | + } | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + $short_codes = []; | |
| 52 | + $current_user = wp_get_current_user(); | |
| 53 | + $user_name = $current_user->user_login; | |
| 54 | + $display_name = $current_user->display_name; | |
| 55 | + $user_email = $current_user->user_email; | |
| 56 | + $app_name = get_bloginfo('name'); | |
| 57 | + | |
| 58 | + // Site shortcodes | |
| 59 | + $short_codes[] = ['key' => 'site_name', 'value' => get_bloginfo( 'name' )]; | |
| 60 | + $short_codes[] = ['key' => 'site_url', 'value' => get_bloginfo( 'url')]; | |
| 61 | + $short_codes[] = ['key' => 'user_name', 'value' => $user_name]; | |
| 62 | + $short_codes[] = ['key' => 'display_name', 'value' => $display_name]; | |
| 63 | + $short_codes[] = ['key' => 'wp_user_email', 'value' => $user_email]; | |
| 64 | + $short_codes[] = ['key' => 'app_name', 'value' => $app_name]; | |
| 65 | + $short_codes[] = ['key' => 'user_login', 'value' => $user_name]; | |
| 66 | + | |
| 67 | + | |
| 68 | + if(is_plugin_active('woocommerce/woocommerce.php')) { | |
| 69 | + | |
| 70 | + // Payment gateway shortcodes | |
| 71 | + $payment_gateways = WC()->payment_gateways()->get_available_payment_gateways(); | |
| 72 | + $first_gateway = !empty($payment_gateways) ? reset($payment_gateways) : null; | |
| 73 | + $admin_email = get_option('admin_email'); | |
| 74 | + $admin_user = get_user_by('email', $admin_email); | |
| 75 | + $short_codes[] = ['key' => 'gateway_title', 'value' => $first_gateway ? $first_gateway->get_method_title() : __('Check Payments', 'emailkit')]; | |
| 76 | + $short_codes[] = ['key' => 'gateway_settings_url', 'value' => $first_gateway ? esc_url(admin_url('admin.php?page=wc-settings&tab=checkout§ion=' . $first_gateway->id)) : esc_url(admin_url('admin.php?page=wc-settings&tab=checkout'))]; | |
| 77 | + $short_codes[] = ['key' => 'username', 'value' => $admin_user ? $admin_user->user_login : $admin_email]; | |
| 78 | + $short_codes[] = ['key' => 'admin_email', 'value' => $admin_email]; | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + $orders = wc_get_orders([ | |
| 83 | + 'limit' => 1, | |
| 84 | + 'orderby' => 'date', | |
| 85 | + 'order' => 'DESC', | |
| 86 | + 'status' => array_keys( wc_get_order_statuses()), | |
| 87 | + ]); | |
| 88 | + | |
| 89 | + if(!empty($orders)) { | |
| 90 | + | |
| 91 | + $order = $orders[0]; | |
| 92 | + | |
| 93 | + | |
| 94 | + foreach($order->get_items() as $item_id => $item) { | |
| 95 | + $product = $item->get_product(); | |
| 96 | + $short_codes[] = ['key' => 'product_name', 'value' => $product->get_name()]; | |
| 97 | + $short_codes[] = ['key' => 'product_price', 'value' => wc_price($product->get_price())]; | |
| 98 | + } | |
| 99 | + | |
| 100 | + $customer = $order->get_user(); | |
| 101 | + | |
| 102 | + // Include customer name and email in the order data | |
| 103 | + if ($customer) { | |
| 104 | + $short_codes[] = ['key' => 'user_login', 'value' => $customer->display_name]; | |
| 105 | + $short_codes[] = ['key' => 'user_email', 'value' => $customer->user_email]; | |
| 106 | + } | |
| 107 | + // Order shortcodes | |
| 108 | + $short_codes[] = ['key' => 'product_name', 'value' => 'T-Shirt with logo']; | |
| 109 | + $short_codes[] = ['key' => 'quantity', 'value' => method_exists($order, 'get_item_count') ? $order->get_item_count() : '2']; | |
| 110 | + $short_codes[] = ['key' => 'order_id', 'value' => method_exists($order, 'get_id') ? $order->get_id() : '1']; | |
| 111 | + $short_codes[] = ['key' => 'order_status', 'value' => method_exists($order, 'get_status') ? $order->get_status() : 'pending']; | |
| 112 | + $short_codes[] = ['key' => 'order_number', 'value' => method_exists($order, 'get_order_number') ? $order->get_order_number() : '1']; | |
| 113 | + $short_codes[] = ['key' => 'order_currency', 'value' => method_exists($order, 'get_currency') ? $order->get_currency() : '$']; | |
| 114 | + $short_codes[] = ['key' => 'order_subtotal', 'value' => method_exists($order, 'get_subtotal') ? wc_price($order->get_subtotal()) : '$0.00']; | |
| 115 | + $short_codes[] = ['key' => 'order_date','value' => method_exists($order, 'get_date_created') ? date_i18n(get_option('date_format'), strtotime(get_date_from_gmt($order->get_date_created()->format('Y-m-d')))): date_i18n(get_option('date_format'), strtotime('2020-01-01')),]; | |
| 116 | + $short_codes[] = ['key' => 'payment_method', 'value' => method_exists($order, 'get_payment_method_title') ? $order->get_payment_method_title() : 'Cash On Delivery']; | |
| 117 | + $short_codes[] = ['key' => 'total', 'value' => method_exists($order, 'get_total') ? wc_price($order->get_total(), 2) : '$0.00']; | |
| 118 | + $short_codes[] = ['key' => 'customer_note', 'value' => method_exists($order, 'get_customer_note') ? ( !empty($order->get_customer_note()) ? $order->get_customer_note() : __('Happy to order', 'emailkit') ) : __('Happy to order', 'emailkit')]; | |
| 119 | + // Billing shortcodes | |
| 120 | + $short_codes[] = ['key' => 'billing_name', 'value' => method_exists($order, 'get_formatted_billing_full_name') ? $order->get_formatted_billing_full_name() : 'Jon Doe']; | |
| 121 | + $short_codes[] = ['key' => 'billing_first_name', 'value' => method_exists($order, 'get_billing_first_name') ? $order->get_billing_first_name() : 'Jon']; | |
| 122 | + $short_codes[] = ['key' => 'billing_last_name', 'value' => method_exists($order, 'get_billing_last_name') ? $order->get_billing_last_name() : 'Doe']; | |
| 123 | + $short_codes[] = ['key' => 'billing_email', 'value' => method_exists($order, 'get_billing_email') ? $order->get_billing_email() : 'jondoe@example.com']; | |
| 124 | + $short_codes[] = ['key' => 'billing_phone', 'value' => method_exists($order, 'get_billing_phone') ? $order->get_billing_phone() : '3456789']; | |
| 125 | + $short_codes[] = ['key' => 'billing_company', 'value' => method_exists($order, 'get_billing_company') ? $order->get_billing_company() : 'xyz.com']; | |
| 126 | + $short_codes[] = ['key' => 'billing_address_1', 'value' => method_exists($order, 'get_billing_address_1') ? $order->get_billing_address_1() : 'USA']; | |
| 127 | + $short_codes[] = ['key' => 'billing_address_2', 'value' => method_exists($order, 'get_billing_address_2') ? $order->get_billing_address_2() : 'USA']; | |
| 128 | + $short_codes[] = ['key' => 'billing_city', 'value' => method_exists($order, 'get_billing_city') ? $order->get_billing_city() : 'USA']; | |
| 129 | + $short_codes[] = ['key' => 'billing_country', 'value' => method_exists($order, 'get_billing_country') ? $order->get_billing_country() : 'America']; | |
| 130 | + $short_codes[] = ['key' => 'billing_postcode', 'value' => method_exists($order, 'get_billing_postcode') ? $order->get_billing_postcode() : '123456']; | |
| 131 | + $short_codes[] = ['key' => 'billing_state', 'value' => method_exists($order, 'get_billing_state') ? $order->get_billing_state() : 'NORTH CAROLINA']; | |
| 132 | + | |
| 133 | + // Shipping shortcodes | |
| 134 | + $short_codes[] = ['key' => 'shipping_first_name', 'value' => method_exists($order, 'get_shipping_first_name') ? $order->get_shipping_first_name() : 'Jon']; | |
| 135 | + $short_codes[] = ['key' => 'shipping_last_name', 'value' => method_exists($order, 'get_shipping_last_name') ? $order->get_shipping_last_name() : 'Doe']; | |
| 136 | + $short_codes[] = ['key' => 'shipping_total', 'value' => method_exists($order, 'get_shipping_total') ? wc_price($order->get_shipping_total()) : '$0.00']; | |
| 137 | + $short_codes[] = ['key' => 'shipping_tax_total', 'value' => method_exists($order, 'get_shipping_tax') ? wc_format_decimal($order->get_shipping_tax(), 2) : '$0.00']; | |
| 138 | + $short_codes[] = ['key' => 'shipping_company', 'value' => method_exists($order, 'get_shipping_company') ? $order->get_shipping_company() : 'xyz.com']; | |
| 139 | + $short_codes[] = ['key' => 'shipping_address_1', 'value' => method_exists($order, 'get_shipping_address_1') ? $order->get_shipping_address_1() : 'USA']; | |
| 140 | + $short_codes[] = ['key' => 'shipping_address_2', 'value' => method_exists($order, 'get_shipping_address_2') ? $order->get_shipping_address_2() : 'USA']; | |
| 141 | + $short_codes[] = ['key' => 'shipping_method', 'value' => method_exists($order, 'get_shipping_method') ? $order->get_shipping_method() : 'Cash']; | |
| 142 | + $short_codes[] = ['key' => 'shipping_city', 'value' => method_exists($order, 'get_shipping_city') ? $order->get_shipping_city() : 'America']; | |
| 143 | + $short_codes[] = ['key' => 'shipping_state', 'value' => method_exists($order, 'get_shipping_state') ? $order->get_shipping_state() : 'North Carolina']; | |
| 144 | + $short_codes[] = ['key' => 'shipping_postcode', 'value' => method_exists($order, 'get_shipping_postcode') ? $order->get_shipping_postcode() : '123456']; | |
| 145 | + $short_codes[] = ['key' => 'shipping_country', 'value' => method_exists($order, 'get_shipping_country') ? $order->get_shipping_country() : 'America']; | |
| 146 | + $short_codes[] = ['key' => 'shipping_phone', 'value' => method_exists($order, 'get_shipping_phone') ? $order->get_shipping_phone() : '3456789']; | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + return [ | |
| 151 | + 'status' => 'success', | |
| 152 | + 'data' => $short_codes, | |
| 153 | + 'message'=> esc_html__( 'WooCommerce order data retrieved successfully.', 'emailkit') | |
| 154 | + ]; | |
| 155 | + } | |
| 156 | + else { | |
| 157 | + | |
| 158 | + return $this->get_demo_data(); | |
| 159 | + } | |
| 160 | + | |
| 161 | + } | |
| 162 | + return $this->get_demo_data(); | |
| 163 | + } | |
| 164 | + | |
| 165 | + public function get_demo_data() { | |
| 166 | + | |
| 167 | + $site_url = get_bloginfo('url'); | |
| 168 | + $current_user = wp_get_current_user(); | |
| 169 | + $user_name = $current_user->user_login; | |
| 170 | + $display_name = $current_user->display_name; | |
| 171 | + $user_email = $current_user->user_email; | |
| 172 | + $app_name = get_bloginfo('name'); | |
| 173 | + | |
| 174 | + $demo_data = [ | |
| 175 | + ['key' => 'order_id', 'value' => '1'], | |
| 176 | + ['key' => 'order_number', 'value' => '1'], | |
| 177 | + ['key' => 'order_status', 'value' => 'pending'], | |
| 178 | + ['key' => 'billing_name', 'value' => 'Jon Doe'], | |
| 179 | + ['key' => 'quantity', 'value' => '2'], | |
| 180 | + ['key' => 'order_currency', 'value' => '$'], | |
| 181 | + ['key' => 'billing_phone', 'value' => '3456789'], | |
| 182 | + ['key' => 'shipping_total', 'value' => '$0.00'], | |
| 183 | + ['key' => 'order_subtotal', 'value' => '$0.00'], | |
| 184 | + ['key' => 'shipping_tax_total', 'value' => '$0.00'], | |
| 185 | + ['key' => 'order_date', 'value' => '2020-01-01 00:00:00'], | |
| 186 | + ['key' => 'shipping_method', 'value' => 'Cash'], | |
| 187 | + ['key' => 'payment_method', 'value' => 'Cash On Delivery'], | |
| 188 | + ['key' => 'total', 'value' => '$0.00'], | |
| 189 | + ['key' => 'billing_first_name', 'value' => 'Jon'], | |
| 190 | + ['key' => 'billing_last_name', 'value' => 'Doe'], | |
| 191 | + ['key' => 'billing_company', 'value' => 'xyz.com'], | |
| 192 | + ['key' => 'billing_address_1', 'value' => 'USA'], | |
| 193 | + ['key' => 'billing_address_2', 'value' => 'USA'], | |
| 194 | + ['key' => 'billing_city', 'value' => 'USA'], | |
| 195 | + ['key' => 'billing_state', 'value' => 'NORTH CAROLINA'], | |
| 196 | + ['key' => 'billing_postcode', 'value' => '123456'], | |
| 197 | + ['key' => 'billing_country', 'value' => 'America'], | |
| 198 | + ['key' => 'billing_email', 'value' => 'jondoe@example.com'], | |
| 199 | + ['key' => 'shipping_first_name', 'value' => 'Jon'], | |
| 200 | + ['key' => 'shipping_last_name', 'value' => 'Doe'], | |
| 201 | + ['key' => 'shipping_company', 'value' => 'xyz.com'], | |
| 202 | + ['key' => 'shipping_address_1', 'value' => 'USA'], | |
| 203 | + ['key' => 'shipping_address_2', 'value' => 'USA'], | |
| 204 | + ['key' => 'shipping_city', 'value' => 'America'], | |
| 205 | + ['key' => 'shipping_state', 'value' => 'North Carolina'], | |
| 206 | + ['key' => 'shipping_postcode', 'value' => '123456'], | |
| 207 | + ['key' => 'shipping_country', 'value' => 'America'], | |
| 208 | + ['key' => 'shipping_phone', 'value' => '3456789'], | |
| 209 | + ['key' => 'customer_note', 'value' => 'Happy To order'], | |
| 210 | + ['key' => 'site_name', 'value' => get_bloginfo( 'name' )], | |
| 211 | + ['key' => 'site_url', 'value' => $site_url], | |
| 212 | + ['key' => 'user_name', 'value' => $user_name], | |
| 213 | + ['key' => 'product_name', 'value' => 'T-Shirt with logo'], | |
| 214 | + ['key' => 'admin_email', 'value' => 'admin@site.com'], | |
| 215 | + ['key' => 'user_login', 'value' => 'admin'], | |
| 216 | + ['key' => 'user_email', 'value' => 'jondoe@example.com'], | |
| 217 | + ['key' => 'site_url', 'value' => $site_url], | |
| 218 | + ['key' => 'display_name', 'value' => $display_name], | |
| 219 | + ['key' => 'wp_user_email', 'value' => $user_email], | |
| 220 | + ['key' => 'app_name', 'value' => $app_name], | |
| 221 | + ['key' => 'gateway_title', 'value' => 'Check Payments'], | |
| 222 | + ['key' => 'gateway_settings_url', 'value' => admin_url('admin.php?page=wc-settings&tab=checkout§ion=cheque')], | |
| 223 | + ['key' => 'username', 'value' => 'admin'], | |
| 224 | + ]; | |
| 225 | + | |
| 226 | + return [ | |
| 227 | + 'status' => 'success', | |
| 228 | + 'data' => $demo_data, | |
| 229 | + 'message' => __( 'No WooCommerce orders found. Returning demo data.', 'emailkit') | |
| 230 | + ]; | |
| 231 | + } | |
| 232 | +} | |