| 1 |
<?php |
| 2 |
|
| 3 |
namespace YayMail\Shortcodes\OrderDetails; |
| 4 |
|
| 5 |
use YayMail\Utils\Helpers; |
| 6 |
use YayMail\Utils\TemplateHelpers; |
| 7 |
use YayMail\Utils\SingletonTrait; |
| 8 |
use YayMail\Abstracts\BaseShortcode; |
| 9 |
|
| 10 |
/** |
| 11 |
* @method: static OrderDetailsShortcodes get_instance() |
| 12 |
*/ |
| 13 |
class OrderDetailsShortcodes extends BaseShortcode { |
| 14 |
use SingletonTrait; |
| 15 |
|
| 16 |
public function get_shortcodes() { |
| 17 |
$shortcodes = []; |
| 18 |
$shortcodes[] = [ |
| 19 |
'name' => 'yaymail_order_id', |
| 20 |
'description' => __( 'Order ID', 'yaymail' ), |
| 21 |
'attributes' => [ |
| 22 |
'is_plain' => false, |
| 23 |
'forced_url' => '', |
| 24 |
], |
| 25 |
'group' => 'order_details', |
| 26 |
'callback' => [ $this, 'yaymail_order_id' ], |
| 27 |
]; |
| 28 |
$shortcodes[] = [ |
| 29 |
'name' => 'yaymail_order_number', |
| 30 |
'description' => __( 'Order Number', 'yaymail' ), |
| 31 |
'attributes' => [ |
| 32 |
'is_plain' => false, |
| 33 |
], |
| 34 |
'group' => 'order_details', |
| 35 |
'callback' => [ $this, 'yaymail_order_number' ], |
| 36 |
]; |
| 37 |
$shortcodes[] = [ |
| 38 |
'name' => 'yaymail_order_date', |
| 39 |
'description' => __( 'Order Date', 'yaymail' ), |
| 40 |
'group' => 'order_details', |
| 41 |
'callback' => [ $this, 'yaymail_order_date' ], |
| 42 |
]; |
| 43 |
$shortcodes[] = [ |
| 44 |
'name' => 'yaymail_order_link', |
| 45 |
'description' => __( 'Order URL', 'yaymail' ), |
| 46 |
'attributes' => [ |
| 47 |
'text_link' => __( 'Order', 'yaymail' ), |
| 48 |
], |
| 49 |
'group' => 'order_details', |
| 50 |
'callback' => [ $this, 'yaymail_order_link' ], |
| 51 |
]; |
| 52 |
$shortcodes[] = [ |
| 53 |
'name' => 'yaymail_order_url', |
| 54 |
'description' => __( 'Order URL (String)', 'yaymail' ), |
| 55 |
'group' => 'order_details', |
| 56 |
'callback' => [ $this, 'yaymail_order_url' ], |
| 57 |
]; |
| 58 |
$shortcodes[] = [ |
| 59 |
'name' => 'yaymail_view_order_link', |
| 60 |
'description' => __( 'View Order Link', 'yaymail' ), |
| 61 |
'attributes' => [ |
| 62 |
'text_link' => __( 'Your Order', 'yaymail' ), |
| 63 |
], |
| 64 |
'group' => 'order_details', |
| 65 |
'callback' => [ $this, 'yaymail_view_order_link' ], |
| 66 |
]; |
| 67 |
$shortcodes[] = [ |
| 68 |
'name' => 'yaymail_view_order_url', |
| 69 |
'description' => __( 'View Order URL (String)', 'yaymail' ), |
| 70 |
'group' => 'order_details', |
| 71 |
'callback' => [ $this, 'yaymail_view_order_url' ], |
| 72 |
]; |
| 73 |
$shortcodes[] = [ |
| 74 |
'name' => 'yaymail_order_status', |
| 75 |
'description' => __( 'Order Status', 'yaymail' ), |
| 76 |
'group' => 'order_details', |
| 77 |
'callback' => [ $this, 'yaymail_order_status' ], |
| 78 |
]; |
| 79 |
$shortcodes[] = [ |
| 80 |
'name' => 'yaymail_order_fee', |
| 81 |
'description' => __( 'Order Fee', 'yaymail' ), |
| 82 |
'group' => 'order_details', |
| 83 |
'callback' => [ $this, 'yaymail_order_fee' ], |
| 84 |
]; |
| 85 |
$shortcodes[] = [ |
| 86 |
'name' => 'yaymail_order_refund', |
| 87 |
'description' => __( 'Order Refund', 'yaymail' ), |
| 88 |
'group' => 'order_details', |
| 89 |
'callback' => [ $this, 'yaymail_order_refund' ], |
| 90 |
]; |
| 91 |
$shortcodes[] = [ |
| 92 |
'name' => 'yaymail_order_subtotal', |
| 93 |
'description' => __( 'Order Subtotal', 'yaymail' ), |
| 94 |
'group' => 'order_details', |
| 95 |
'callback' => [ $this, 'yaymail_order_subtotal' ], |
| 96 |
]; |
| 97 |
$shortcodes[] = [ |
| 98 |
'name' => 'yaymail_order_total', |
| 99 |
'description' => __( 'Order Total', 'yaymail' ), |
| 100 |
'group' => 'order_details', |
| 101 |
'callback' => [ $this, 'yaymail_order_total' ], |
| 102 |
]; |
| 103 |
$shortcodes[] = [ |
| 104 |
'name' => 'yaymail_order_total_value', |
| 105 |
'description' => __( 'Order Total Value', 'yaymail' ), |
| 106 |
'group' => 'order_details', |
| 107 |
'callback' => [ $this, 'yaymail_order_total_value' ], |
| 108 |
]; |
| 109 |
$shortcodes[] = [ |
| 110 |
'name' => 'yaymail_order_coupon_codes', |
| 111 |
'description' => __( 'Order Coupon Codes', 'yaymail' ), |
| 112 |
'group' => 'order_details', |
| 113 |
'callback' => [ $this, 'yaymail_order_coupon_codes' ], |
| 114 |
]; |
| 115 |
$shortcodes[] = [ |
| 116 |
'name' => 'yaymail_order_product_line_item_count', |
| 117 |
'description' => __( 'Number of line items in the order', 'yaymail' ), |
| 118 |
'group' => 'order_details', |
| 119 |
'callback' => [ $this, 'yaymail_order_product_line_item_count' ], |
| 120 |
]; |
| 121 |
$shortcodes[] = [ |
| 122 |
'name' => 'yaymail_order_product_line_item_count_double', |
| 123 |
'description' => __( 'Number of line items in the order (double)', 'yaymail' ), |
| 124 |
'group' => 'order_details', |
| 125 |
'callback' => [ $this, 'yaymail_order_product_line_item_count_double' ], |
| 126 |
]; |
| 127 |
$shortcodes[] = [ |
| 128 |
'name' => 'yaymail_order_product_item_count', |
| 129 |
'description' => __( 'Total quantity of all items in the order', 'yaymail' ), |
| 130 |
'group' => 'order_details', |
| 131 |
'callback' => [ $this, 'yaymail_order_product_item_count' ], |
| 132 |
]; |
| 133 |
$shortcodes[] = [ |
| 134 |
'name' => 'yaymail_order_product_count', |
| 135 |
'description' => __( 'Number of base products in the order', 'yaymail' ), |
| 136 |
'group' => 'order_details', |
| 137 |
'callback' => [ $this, 'yaymail_order_product_count' ], |
| 138 |
]; |
| 139 |
$shortcodes[] = [ |
| 140 |
'name' => 'yaymail_order_product_variation_count', |
| 141 |
'description' => __( 'Number of product variations in the order', 'yaymail' ), |
| 142 |
'group' => 'order_details', |
| 143 |
'callback' => [ $this, 'yaymail_order_product_variation_count' ], |
| 144 |
]; |
| 145 |
$shortcodes[] = [ |
| 146 |
'name' => 'yaymail_customer_roles', |
| 147 |
'description' => __( 'Customer Roles', 'yaymail' ), |
| 148 |
'group' => 'order_details', |
| 149 |
'callback' => [ $this, 'yaymail_customer_roles' ], |
| 150 |
]; |
| 151 |
$shortcodes[] = [ |
| 152 |
'name' => 'yaymail_customer_note', |
| 153 |
'description' => __( 'Customer Last Note', 'yaymail' ), |
| 154 |
'group' => 'order_details', |
| 155 |
'callback' => [ $this, 'yaymail_customer_note' ], |
| 156 |
]; |
| 157 |
$shortcodes[] = [ |
| 158 |
'name' => 'yaymail_customer_notes', |
| 159 |
'description' => __( 'All Customer Note', 'yaymail' ), |
| 160 |
'group' => 'order_details', |
| 161 |
'callback' => [ $this, 'yaymail_customer_notes' ], |
| 162 |
]; |
| 163 |
$shortcodes[] = [ |
| 164 |
'name' => 'yaymail_customer_provided_note', |
| 165 |
'description' => __( 'Customer Provided Note', 'yaymail' ), |
| 166 |
'group' => 'order_details', |
| 167 |
'callback' => [ $this, 'yaymail_customer_provided_note' ], |
| 168 |
]; |
| 169 |
$shortcodes[] = [ |
| 170 |
'name' => 'woocommerce_email_order_meta', |
| 171 |
'description' => __( 'Order Meta Content', 'yaymail' ), |
| 172 |
'group' => 'order_details', |
| 173 |
'callback' => [ $this, 'woocommerce_email_order_meta' ], |
| 174 |
]; |
| 175 |
$shortcodes[] = [ |
| 176 |
'name' => 'yaymail_order_details', |
| 177 |
'description' => __( 'Order Details', 'yaymail' ), |
| 178 |
'group' => 'order_details', |
| 179 |
'attributes' => [ |
| 180 |
'product_title' => 'Product', |
| 181 |
'quantity_title' => 'Quantity', |
| 182 |
'price_title' => 'Price', |
| 183 |
'total_title' => 'Total', |
| 184 |
'cart_subtotal_title' => 'Subtotal', |
| 185 |
'shipping_title' => 'Shipping', |
| 186 |
'payment_method_title' => 'Payment method', |
| 187 |
'order_total_title' => 'Total', |
| 188 |
'show_product_item_cost' => 'false', |
| 189 |
], |
| 190 |
'callback' => [ $this, 'yaymail_order_details' ], |
| 191 |
]; |
| 192 |
$shortcodes[] = [ |
| 193 |
'name' => 'yaymail_order_details_download_product', |
| 194 |
'description' => __( 'Order Details Download Product', 'yaymail' ), |
| 195 |
'group' => '', |
| 196 |
'attributes' => [ |
| 197 |
'product_title' => 'Product', |
| 198 |
'quantity_title' => 'Quantity', |
| 199 |
'price_title' => 'Price', |
| 200 |
'total_title' => 'Total', |
| 201 |
'cart_subtotal_title' => 'Subtotal', |
| 202 |
'shipping_title' => 'Shipping', |
| 203 |
'payment_method_title' => 'Payment method', |
| 204 |
'order_total_title' => 'Total', |
| 205 |
'show_product_item_cost' => 'false', |
| 206 |
], |
| 207 |
'callback' => [ $this, 'yaymail_order_details_download_product' ], |
| 208 |
]; |
| 209 |
|
| 210 |
return $shortcodes; |
| 211 |
} |
| 212 |
|
| 213 |
/** |
| 214 |
* Render order details shortcode |
| 215 |
* |
| 216 |
* @param array $args |
| 217 |
* $render_data |
| 218 |
* $element |
| 219 |
* $settings |
| 220 |
* $is_placeholder |
| 221 |
*/ |
| 222 |
public static function yaymail_order_details( $args ) { |
| 223 |
|
| 224 |
$render_data = isset( $args['render_data'] ) ? $args['render_data'] : []; |
| 225 |
|
| 226 |
if ( ! empty( $render_data['is_sample'] ) ) { |
| 227 |
/** |
| 228 |
* Is sample order |
| 229 |
*/ |
| 230 |
$html = yaymail_get_content( 'templates/shortcodes/order-details/sample.php', $args ); |
| 231 |
return $html; |
| 232 |
} |
| 233 |
|
| 234 |
if ( empty( $render_data['order'] ) ) { |
| 235 |
/** |
| 236 |
* Not having order/order_id |
| 237 |
*/ |
| 238 |
return ''; |
| 239 |
} |
| 240 |
|
| 241 |
$html = yaymail_get_content( 'templates/shortcodes/order-details/main.php', $args ); |
| 242 |
return $html; |
| 243 |
} |
| 244 |
|
| 245 |
public static function yaymail_order_details_download_product( $args ) { |
| 246 |
|
| 247 |
$render_data = isset( $args['render_data'] ) ? $args['render_data'] : []; |
| 248 |
|
| 249 |
if ( ! empty( $render_data['is_sample'] ) ) { |
| 250 |
/** |
| 251 |
* Is sample order |
| 252 |
*/ |
| 253 |
$html = yaymail_get_content( 'templates/shortcodes/order-details-download-product/sample.php', $args ); |
| 254 |
return $html; |
| 255 |
} |
| 256 |
|
| 257 |
if ( empty( $render_data['order'] ) ) { |
| 258 |
/** |
| 259 |
* Not having order/order_id |
| 260 |
*/ |
| 261 |
return ''; |
| 262 |
} |
| 263 |
|
| 264 |
$html = yaymail_get_content( 'templates/shortcodes/order-details-download-product/main.php', $args ); |
| 265 |
return $html; |
| 266 |
} |
| 267 |
|
| 268 |
public function yaymail_order_id( $data, $shortcode_atts ) { |
| 269 |
|
| 270 |
$render_data = isset( $data['render_data'] ) ? $data['render_data'] : []; |
| 271 |
$is_placeholder = isset( $data['is_placeholder'] ) ? $data['is_placeholder'] : false; |
| 272 |
$is_customized_preview = isset( $render_data['is_customized_preview'] ) ? $render_data['is_customized_preview'] : false; |
| 273 |
$is_plain = isset( $shortcode_atts['is_plain'] ) ? Helpers::is_true( $shortcode_atts['is_plain'] ) : false; |
| 274 |
|
| 275 |
if ( ! empty( $render_data['is_sample'] ) ) { |
| 276 |
/** |
| 277 |
* Is sample order |
| 278 |
*/ |
| 279 |
|
| 280 |
if ( ! $is_plain ) { |
| 281 |
return '<a href="#">1</a>'; |
| 282 |
} |
| 283 |
|
| 284 |
return '1'; |
| 285 |
} |
| 286 |
|
| 287 |
$order = Helpers::get_order_from_shortcode_data( $render_data ); |
| 288 |
|
| 289 |
if ( empty( $order ) ) { |
| 290 |
/** |
| 291 |
* Not having order_id |
| 292 |
*/ |
| 293 |
return ''; |
| 294 |
} |
| 295 |
|
| 296 |
$sent_to_admin = isset( $render_data['sent_to_admin'] ) ? $render_data['sent_to_admin'] : false; |
| 297 |
|
| 298 |
$template = ! empty( $data['template'] ) ? $data['template'] : null; |
| 299 |
|
| 300 |
$text_link_color = ! empty( $template ) ? $template->get_text_link_color() : YAYMAIL_COLOR_WC_DEFAULT; |
| 301 |
|
| 302 |
$element_type = isset( $data['element']['type'] ) ? $data['element']['type'] : ''; |
| 303 |
|
| 304 |
$link_style = TemplateHelpers::get_style( |
| 305 |
[ |
| 306 |
'color' => 'heading' === $element_type ? 'inherit' : $text_link_color, |
| 307 |
'text-decoration' => 'heading' !== $element_type ? 'underline' : 'none', |
| 308 |
] |
| 309 |
); |
| 310 |
|
| 311 |
$forced_url = ''; |
| 312 |
|
| 313 |
if ( isset( $shortcode_atts['forced_url'] ) ) { |
| 314 |
$forced_url = filter_var( $shortcode_atts['forced_url'], FILTER_VALIDATE_URL ) === false ? '' : $shortcode_atts['forced_url']; |
| 315 |
} |
| 316 |
|
| 317 |
$url = ! empty( $forced_url ) ? do_shortcode( $forced_url ) : $order->get_edit_order_url(); |
| 318 |
|
| 319 |
// If not plain text and (placeholder or customized preview or sent to admin), show as link |
| 320 |
if ( ! $is_plain && ( $is_placeholder || $is_customized_preview || $sent_to_admin ) ) { |
| 321 |
return wp_kses_post( "<a style='$link_style' href='{$url}'>{$order->get_id()}</a>" ); |
| 322 |
} |
| 323 |
|
| 324 |
// If is_plain is true, return just the order ID without link |
| 325 |
return $order->get_id(); |
| 326 |
} |
| 327 |
|
| 328 |
public function yaymail_order_number( $data, $shortcode_atts = [] ) { |
| 329 |
|
| 330 |
$render_data = isset( $data['render_data'] ) ? $data['render_data'] : []; |
| 331 |
$is_placeholder = isset( $data['is_placeholder'] ) ? $data['is_placeholder'] : false; |
| 332 |
$is_customized_preview = isset( $render_data['is_customized_preview'] ) ? $render_data['is_customized_preview'] : false; |
| 333 |
$is_plain = isset( $shortcode_atts['is_plain'] ) ? Helpers::is_true( $shortcode_atts['is_plain'] ) : false; |
| 334 |
|
| 335 |
if ( ! empty( $render_data['is_sample'] ) ) { |
| 336 |
/** |
| 337 |
* Is sample order |
| 338 |
*/ |
| 339 |
|
| 340 |
if ( ! $is_plain ) { |
| 341 |
return '<a href="#">1</a>'; |
| 342 |
} |
| 343 |
|
| 344 |
return '1'; |
| 345 |
} |
| 346 |
|
| 347 |
$order = Helpers::get_order_from_shortcode_data( $render_data ); |
| 348 |
|
| 349 |
if ( empty( $order ) ) { |
| 350 |
/** |
| 351 |
* Not having order_id |
| 352 |
*/ |
| 353 |
return ''; |
| 354 |
} |
| 355 |
|
| 356 |
$template = ! empty( $data['template'] ) ? $data['template'] : null; |
| 357 |
|
| 358 |
$text_link_color = ! empty( $template ) ? $template->get_text_link_color() : YAYMAIL_COLOR_WC_DEFAULT; |
| 359 |
|
| 360 |
$sent_to_admin = isset( $render_data['sent_to_admin'] ) ? $render_data['sent_to_admin'] : false; |
| 361 |
|
| 362 |
if ( ! $is_plain && ( $is_placeholder || $is_customized_preview || $sent_to_admin ) ) { |
| 363 |
// $sent_to_admin === true |
| 364 |
return wp_kses_post( "<a style='$text_link_color' href='{$order->get_edit_order_url()}'>{$order->get_order_number()}</a>" ); |
| 365 |
} |
| 366 |
|
| 367 |
return $order->get_order_number(); |
| 368 |
} |
| 369 |
|
| 370 |
public function yaymail_order_link( $data, $shortcode_atts = [] ) { |
| 371 |
$order_url = $this->yaymail_order_url( $data ); |
| 372 |
|
| 373 |
if ( empty( $order_url ) ) { |
| 374 |
return ''; |
| 375 |
} |
| 376 |
|
| 377 |
$is_placeholder = isset( $data['is_placeholder'] ) ? $data['is_placeholder'] : false; |
| 378 |
|
| 379 |
$text_link = isset( $shortcode_atts['text_link'] ) ? $shortcode_atts['text_link'] : TemplateHelpers::get_content_as_placeholder( 'text_link', __( 'Order', 'yaymail' ), $is_placeholder ); |
| 380 |
|
| 381 |
return wp_kses_post( "<a href='{$order_url}'>" . $text_link . '</a>' ); |
| 382 |
} |
| 383 |
|
| 384 |
public function yaymail_order_url( $data ) { |
| 385 |
|
| 386 |
$render_data = isset( $data['render_data'] ) ? $data['render_data'] : []; |
| 387 |
|
| 388 |
if ( ! empty( $render_data['is_sample'] ) ) { |
| 389 |
/** |
| 390 |
* Is sample order |
| 391 |
*/ |
| 392 |
return esc_url( get_home_url() ); |
| 393 |
} |
| 394 |
|
| 395 |
$order = Helpers::get_order_from_shortcode_data( $render_data ); |
| 396 |
|
| 397 |
if ( empty( $order ) ) { |
| 398 |
/** |
| 399 |
* Not having order_id |
| 400 |
*/ |
| 401 |
return ''; |
| 402 |
} |
| 403 |
|
| 404 |
$sent_to_admin = isset( $render_data['sent_to_admin'] ) ? $render_data['sent_to_admin'] : false; |
| 405 |
|
| 406 |
$order_url = $sent_to_admin ? $order->get_edit_order_url() : $order->get_view_order_url(); |
| 407 |
|
| 408 |
if ( empty( $order_url ) ) { |
| 409 |
return ''; |
| 410 |
} |
| 411 |
|
| 412 |
return esc_url( $order_url ); |
| 413 |
} |
| 414 |
|
| 415 |
public function yaymail_view_order_link( $data, $shortcode_atts = [] ) { |
| 416 |
|
| 417 |
$render_data = isset( $data['render_data'] ) ? $data['render_data'] : []; |
| 418 |
|
| 419 |
$is_placeholder = isset( $data['is_placeholder'] ) ? $data['is_placeholder'] : false; |
| 420 |
|
| 421 |
$text_link = isset( $shortcode_atts['text_link'] ) ? $shortcode_atts['text_link'] : TemplateHelpers::get_content_as_placeholder( 'text_link', __( 'Your Order', 'yaymail' ), $is_placeholder ); |
| 422 |
|
| 423 |
if ( ! empty( $render_data['is_sample'] ) ) { |
| 424 |
/** |
| 425 |
* Is sample order |
| 426 |
*/ |
| 427 |
return '<a href="' . esc_url( get_home_url() ) . '">' . $text_link . '</a>'; |
| 428 |
} |
| 429 |
|
| 430 |
$order = Helpers::get_order_from_shortcode_data( $render_data ); |
| 431 |
|
| 432 |
if ( empty( $order ) ) { |
| 433 |
/** |
| 434 |
* Not having order_id |
| 435 |
*/ |
| 436 |
return ''; |
| 437 |
} |
| 438 |
|
| 439 |
$view_order_url = $order->get_view_order_url(); |
| 440 |
|
| 441 |
if ( empty( $view_order_url ) ) { |
| 442 |
return ''; |
| 443 |
} |
| 444 |
|
| 445 |
return wp_kses_post( "<a href='{$view_order_url}'>" . $text_link . '</a>' ); |
| 446 |
} |
| 447 |
|
| 448 |
public function yaymail_view_order_url( $data ) { |
| 449 |
|
| 450 |
$render_data = isset( $data['render_data'] ) ? $data['render_data'] : []; |
| 451 |
|
| 452 |
if ( ! empty( $render_data['is_sample'] ) ) { |
| 453 |
/** |
| 454 |
* Is sample order |
| 455 |
*/ |
| 456 |
return esc_url( get_home_url() ); |
| 457 |
} |
| 458 |
|
| 459 |
$order = Helpers::get_order_from_shortcode_data( $render_data ); |
| 460 |
|
| 461 |
if ( empty( $order ) ) { |
| 462 |
/** |
| 463 |
* Not having order_id |
| 464 |
*/ |
| 465 |
return ''; |
| 466 |
} |
| 467 |
|
| 468 |
$view_order_url = $order->get_view_order_url(); |
| 469 |
|
| 470 |
if ( empty( $view_order_url ) ) { |
| 471 |
return ''; |
| 472 |
} |
| 473 |
|
| 474 |
return esc_url( $view_order_url ); |
| 475 |
} |
| 476 |
|
| 477 |
public function yaymail_order_date( $data ) { |
| 478 |
|
| 479 |
$render_data = isset( $data['render_data'] ) ? $data['render_data'] : []; |
| 480 |
|
| 481 |
if ( ! empty( $render_data['is_sample'] ) ) { |
| 482 |
/** |
| 483 |
* Is sample order |
| 484 |
*/ |
| 485 |
return date_i18n( function_exists( 'wc_date_format' ) ? wc_date_format() : get_option( 'date_format' ) ); |
| 486 |
} |
| 487 |
|
| 488 |
$order = Helpers::get_order_from_shortcode_data( $render_data ); |
| 489 |
|
| 490 |
if ( empty( $order ) ) { |
| 491 |
/** |
| 492 |
* Not having order_id |
| 493 |
*/ |
| 494 |
return ''; |
| 495 |
} |
| 496 |
|
| 497 |
$order_created_date = $order->get_date_created(); |
| 498 |
|
| 499 |
if ( empty( $order_created_date ) ) { |
| 500 |
return ''; |
| 501 |
} |
| 502 |
|
| 503 |
return $order_created_date->date_i18n( function_exists( 'wc_date_format' ) ? wc_date_format() : get_option( 'date_format' ) ); |
| 504 |
} |
| 505 |
|
| 506 |
public function yaymail_order_status( $data ) { |
| 507 |
$render_data = isset( $data['render_data'] ) ? $data['render_data'] : []; |
| 508 |
|
| 509 |
if ( ! empty( $render_data['is_sample'] ) ) { |
| 510 |
/** |
| 511 |
* Is sample order |
| 512 |
*/ |
| 513 |
return __( 'sample status', 'yaymail' ); |
| 514 |
} |
| 515 |
|
| 516 |
$order = Helpers::get_order_from_shortcode_data( $render_data ); |
| 517 |
|
| 518 |
if ( empty( $order ) ) { |
| 519 |
/** |
| 520 |
* Not having order_id |
| 521 |
*/ |
| 522 |
return ''; |
| 523 |
} |
| 524 |
|
| 525 |
$status = $order->get_status(); |
| 526 |
|
| 527 |
if ( empty( $status ) ) { |
| 528 |
return ''; |
| 529 |
} |
| 530 |
|
| 531 |
return strtolower( wc_get_order_status_name( $status ) ); |
| 532 |
} |
| 533 |
|
| 534 |
public function yaymail_order_fee( $data ) { |
| 535 |
$render_data = isset( $data['render_data'] ) ? $data['render_data'] : []; |
| 536 |
|
| 537 |
if ( ! empty( $render_data['is_sample'] ) ) { |
| 538 |
/** |
| 539 |
* Is sample order |
| 540 |
*/ |
| 541 |
return 0; |
| 542 |
} |
| 543 |
|
| 544 |
$order = Helpers::get_order_from_shortcode_data( $render_data ); |
| 545 |
|
| 546 |
if ( empty( $order ) ) { |
| 547 |
/** |
| 548 |
* Not having order_id |
| 549 |
*/ |
| 550 |
return ''; |
| 551 |
} |
| 552 |
|
| 553 |
$fee = 0; |
| 554 |
|
| 555 |
$order_totals = $order->get_order_item_totals(); |
| 556 |
|
| 557 |
if ( ! empty( $order_totals ) ) { |
| 558 |
foreach ( $order_totals as $index => $value ) { |
| 559 |
if ( strpos( $index, 'fee' ) !== false ) { |
| 560 |
$fees = $order->get_fees(); |
| 561 |
foreach ( $fees as $fee_val ) { |
| 562 |
if ( method_exists( $fee_val, 'get_amount' ) ) { |
| 563 |
$fee += (float) $fee_val->get_amount(); |
| 564 |
} |
| 565 |
} |
| 566 |
} |
| 567 |
} |
| 568 |
} |
| 569 |
|
| 570 |
return $fee; |
| 571 |
} |
| 572 |
|
| 573 |
public function yaymail_order_refund( $data ) { |
| 574 |
$render_data = isset( $data['render_data'] ) ? $data['render_data'] : []; |
| 575 |
|
| 576 |
if ( ! empty( $render_data['is_sample'] ) ) { |
| 577 |
/** |
| 578 |
* Is sample order |
| 579 |
*/ |
| 580 |
return wc_price( 0 ); |
| 581 |
} |
| 582 |
|
| 583 |
$order = Helpers::get_order_from_shortcode_data( $render_data ); |
| 584 |
|
| 585 |
if ( empty( $order ) ) { |
| 586 |
/** |
| 587 |
* Not having order_id |
| 588 |
*/ |
| 589 |
return ''; |
| 590 |
} |
| 591 |
|
| 592 |
$refund = 0; |
| 593 |
|
| 594 |
$order_totals = $order->get_order_item_totals(); |
| 595 |
|
| 596 |
if ( ! empty( $order_totals ) ) { |
| 597 |
foreach ( $order_totals as $index => $value ) { |
| 598 |
if ( strpos( $index, 'refund' ) !== false ) { |
| 599 |
$refund = $order->get_total_refunded(); |
| 600 |
} |
| 601 |
} |
| 602 |
} |
| 603 |
|
| 604 |
return wc_price( $refund, [ 'currency' => $order->get_currency() ] ); |
| 605 |
} |
| 606 |
|
| 607 |
public function yaymail_order_subtotal( $data ) { |
| 608 |
$render_data = isset( $data['render_data'] ) ? $data['render_data'] : []; |
| 609 |
|
| 610 |
if ( ! empty( $render_data['is_sample'] ) ) { |
| 611 |
/** |
| 612 |
* Is sample order |
| 613 |
*/ |
| 614 |
return wc_price( '18.00' ); |
| 615 |
} |
| 616 |
|
| 617 |
$order = Helpers::get_order_from_shortcode_data( $render_data ); |
| 618 |
|
| 619 |
if ( empty( $order ) ) { |
| 620 |
/** |
| 621 |
* Not having order_id |
| 622 |
*/ |
| 623 |
return ''; |
| 624 |
} |
| 625 |
|
| 626 |
$order_totals = $order->get_order_item_totals(); |
| 627 |
|
| 628 |
if ( empty( $order_totals ) ) { |
| 629 |
return ''; |
| 630 |
} |
| 631 |
|
| 632 |
if ( ! empty( $order_totals['cart_subtotal'] ) && isset( $order_totals['cart_subtotal']['value'] ) ) { |
| 633 |
return $order_totals['cart_subtotal']['value']; |
| 634 |
} else { |
| 635 |
return ''; |
| 636 |
} |
| 637 |
} |
| 638 |
|
| 639 |
public function yaymail_order_total( $data ) { |
| 640 |
$render_data = isset( $data['render_data'] ) ? $data['render_data'] : []; |
| 641 |
|
| 642 |
if ( ! empty( $render_data['is_sample'] ) ) { |
| 643 |
/** |
| 644 |
* Is sample order |
| 645 |
*/ |
| 646 |
return wc_price( '18.00' ); |
| 647 |
} |
| 648 |
|
| 649 |
$order = Helpers::get_order_from_shortcode_data( $render_data ); |
| 650 |
|
| 651 |
if ( empty( $order ) ) { |
| 652 |
/** |
| 653 |
* Not having order_id |
| 654 |
*/ |
| 655 |
return ''; |
| 656 |
} |
| 657 |
|
| 658 |
return wc_price( $order->get_total(), [ 'currency' => $order->get_currency() ] ); |
| 659 |
} |
| 660 |
|
| 661 |
public function yaymail_order_total_value( $data ) { |
| 662 |
$render_data = isset( $data['render_data'] ) ? $data['render_data'] : []; |
| 663 |
|
| 664 |
if ( ! empty( $render_data['is_sample'] ) ) { |
| 665 |
/** |
| 666 |
* Is sample order |
| 667 |
*/ |
| 668 |
return '18.00'; |
| 669 |
} |
| 670 |
|
| 671 |
$order = Helpers::get_order_from_shortcode_data( $render_data ); |
| 672 |
|
| 673 |
if ( empty( $order ) ) { |
| 674 |
/** |
| 675 |
* Not having order_id |
| 676 |
*/ |
| 677 |
return ''; |
| 678 |
} |
| 679 |
|
| 680 |
return $order->get_total(); |
| 681 |
} |
| 682 |
|
| 683 |
public function yaymail_order_coupon_codes( $data ) { |
| 684 |
$render_data = isset( $data['render_data'] ) ? $data['render_data'] : []; |
| 685 |
|
| 686 |
if ( ! empty( $render_data['is_sample'] ) ) { |
| 687 |
/** |
| 688 |
* Is sample order |
| 689 |
*/ |
| 690 |
return 'sample_code'; |
| 691 |
} |
| 692 |
|
| 693 |
$order = Helpers::get_order_from_shortcode_data( $render_data ); |
| 694 |
|
| 695 |
if ( empty( $order ) ) { |
| 696 |
/** |
| 697 |
* Not having order_id |
| 698 |
*/ |
| 699 |
return ''; |
| 700 |
} |
| 701 |
|
| 702 |
$order_coupon_codes = ''; |
| 703 |
|
| 704 |
if ( method_exists( $order, 'get_coupon_codes' ) && ! empty( $order->get_coupon_codes() ) ) { |
| 705 |
$coupon_codes = $order->get_coupon_codes(); |
| 706 |
foreach ( $coupon_codes as $coupon_code ) { |
| 707 |
$order_coupon_codes .= wp_kses_post( $coupon_code ); |
| 708 |
} |
| 709 |
} |
| 710 |
return $order_coupon_codes; |
| 711 |
} |
| 712 |
|
| 713 |
public function yaymail_order_product_line_item_count( $data ) { |
| 714 |
$render_data = isset( $data['render_data'] ) ? $data['render_data'] : []; |
| 715 |
|
| 716 |
if ( ! empty( $render_data['is_sample'] ) ) { |
| 717 |
/** |
| 718 |
* Is sample order |
| 719 |
*/ |
| 720 |
return '1'; |
| 721 |
} |
| 722 |
|
| 723 |
$order = Helpers::get_order_from_shortcode_data( $render_data ); |
| 724 |
|
| 725 |
if ( empty( $order ) ) { |
| 726 |
/** |
| 727 |
* Not having order_id |
| 728 |
*/ |
| 729 |
return ''; |
| 730 |
} |
| 731 |
|
| 732 |
return count( $order->get_items() ); |
| 733 |
} |
| 734 |
|
| 735 |
public function yaymail_order_product_line_item_count_double( $data ) { |
| 736 |
$render_data = isset( $data['render_data'] ) ? $data['render_data'] : []; |
| 737 |
|
| 738 |
if ( ! empty( $render_data['is_sample'] ) ) { |
| 739 |
/** |
| 740 |
* Is sample order |
| 741 |
*/ |
| 742 |
return '2'; |
| 743 |
} |
| 744 |
|
| 745 |
$order = Helpers::get_order_from_shortcode_data( $render_data ); |
| 746 |
|
| 747 |
if ( empty( $order ) ) { |
| 748 |
/** |
| 749 |
* Not having order_id |
| 750 |
*/ |
| 751 |
return ''; |
| 752 |
} |
| 753 |
|
| 754 |
return count( $order->get_items() ) * 2; |
| 755 |
} |
| 756 |
|
| 757 |
public function yaymail_order_product_item_count( $data ) { |
| 758 |
$render_data = isset( $data['render_data'] ) ? $data['render_data'] : []; |
| 759 |
|
| 760 |
if ( ! empty( $render_data['is_sample'] ) ) { |
| 761 |
/** |
| 762 |
* Is sample order |
| 763 |
*/ |
| 764 |
return '1'; |
| 765 |
} |
| 766 |
|
| 767 |
$order = Helpers::get_order_from_shortcode_data( $render_data ); |
| 768 |
|
| 769 |
if ( empty( $order ) ) { |
| 770 |
/** |
| 771 |
* Not having order_id |
| 772 |
*/ |
| 773 |
return ''; |
| 774 |
} |
| 775 |
|
| 776 |
return $order->get_item_count(); |
| 777 |
} |
| 778 |
|
| 779 |
public function yaymail_order_product_count( $data ) { |
| 780 |
$render_data = isset( $data['render_data'] ) ? $data['render_data'] : []; |
| 781 |
|
| 782 |
if ( ! empty( $render_data['is_sample'] ) ) { |
| 783 |
/** |
| 784 |
* Is sample order |
| 785 |
*/ |
| 786 |
return '1'; |
| 787 |
} |
| 788 |
|
| 789 |
$order = Helpers::get_order_from_shortcode_data( $render_data ); |
| 790 |
|
| 791 |
if ( empty( $order ) ) { |
| 792 |
/** |
| 793 |
* Not having order_id |
| 794 |
*/ |
| 795 |
return ''; |
| 796 |
} |
| 797 |
|
| 798 |
$products_in_order = []; |
| 799 |
foreach ( $order->get_items() as $item ) { |
| 800 |
$product = $item->get_product(); |
| 801 |
if ( ! empty( $product ) ) { |
| 802 |
if ( $product->is_type( 'variation' ) ) { |
| 803 |
$products_in_order[] = $product->get_parent_id(); |
| 804 |
} else { |
| 805 |
$products_in_order[] = $product->get_id(); |
| 806 |
} |
| 807 |
} |
| 808 |
} |
| 809 |
|
| 810 |
return count( array_unique( $products_in_order ) ); |
| 811 |
} |
| 812 |
|
| 813 |
public function yaymail_order_product_variation_count( $data ) { |
| 814 |
$render_data = isset( $data['render_data'] ) ? $data['render_data'] : []; |
| 815 |
|
| 816 |
if ( ! empty( $render_data['is_sample'] ) ) { |
| 817 |
/** |
| 818 |
* Is sample order |
| 819 |
*/ |
| 820 |
return '1'; |
| 821 |
} |
| 822 |
|
| 823 |
$order = Helpers::get_order_from_shortcode_data( $render_data ); |
| 824 |
|
| 825 |
if ( empty( $order ) ) { |
| 826 |
/** |
| 827 |
* Not having order_id |
| 828 |
*/ |
| 829 |
return ''; |
| 830 |
} |
| 831 |
|
| 832 |
$products_in_order = []; |
| 833 |
foreach ( $order->get_items() as $item ) { |
| 834 |
$product = $item->get_product(); |
| 835 |
if ( ! empty( $product ) ) { |
| 836 |
$products_in_order[] = $product->get_id(); |
| 837 |
} |
| 838 |
} |
| 839 |
|
| 840 |
return count( array_unique( $products_in_order ) ); |
| 841 |
} |
| 842 |
|
| 843 |
public function yaymail_customer_roles( $data ) { |
| 844 |
$render_data = isset( $data['render_data'] ) ? $data['render_data'] : []; |
| 845 |
|
| 846 |
if ( ! empty( $render_data['is_sample'] ) ) { |
| 847 |
/** |
| 848 |
* Is sample order |
| 849 |
*/ |
| 850 |
$current_user = wp_get_current_user(); |
| 851 |
if ( ! empty( $current_user ) && isset( $current_user->roles ) && ! empty( $current_user->roles ) ) { |
| 852 |
return implode( ', ', $current_user->roles ); |
| 853 |
} |
| 854 |
return ''; |
| 855 |
} |
| 856 |
|
| 857 |
$order = Helpers::get_order_from_shortcode_data( $render_data ); |
| 858 |
|
| 859 |
if ( empty( $order ) ) { |
| 860 |
/** |
| 861 |
* Not having order_id |
| 862 |
*/ |
| 863 |
return ''; |
| 864 |
} |
| 865 |
|
| 866 |
$user = $order->get_user(); |
| 867 |
if ( ! empty( $user ) && isset( $user->roles ) && ! empty( $user->roles ) ) { |
| 868 |
return implode( ', ', $user->roles ); |
| 869 |
} |
| 870 |
return ''; |
| 871 |
} |
| 872 |
|
| 873 |
public function yaymail_customer_note( $data ) { |
| 874 |
$render_data = isset( $data['render_data'] ) ? $data['render_data'] : []; |
| 875 |
|
| 876 |
if ( ! empty( $render_data['is_sample'] ) ) { |
| 877 |
/** |
| 878 |
* Is sample order |
| 879 |
*/ |
| 880 |
return __( 'customer note', 'yaymail' ); |
| 881 |
} |
| 882 |
|
| 883 |
$order = Helpers::get_order_from_shortcode_data( $render_data ); |
| 884 |
|
| 885 |
if ( empty( $order ) ) { |
| 886 |
/** |
| 887 |
* Not having order_id |
| 888 |
*/ |
| 889 |
return ''; |
| 890 |
} |
| 891 |
|
| 892 |
$order_notes = $order->get_customer_order_notes(); |
| 893 |
if ( ! empty( $order_notes ) && count( $order_notes ) > 0 ) { |
| 894 |
return wp_kses_post( wpautop( wptexturize( make_clickable( $order_notes[0]->comment_content ) ) ) ); |
| 895 |
} |
| 896 |
return ''; |
| 897 |
} |
| 898 |
|
| 899 |
public function yaymail_customer_notes( $data ) { |
| 900 |
$render_data = isset( $data['render_data'] ) ? $data['render_data'] : []; |
| 901 |
|
| 902 |
if ( ! empty( $render_data['is_sample'] ) ) { |
| 903 |
/** |
| 904 |
* Is sample order |
| 905 |
*/ |
| 906 |
return __( 'customer notes', 'yaymail' ); |
| 907 |
} |
| 908 |
|
| 909 |
$order = Helpers::get_order_from_shortcode_data( $render_data ); |
| 910 |
|
| 911 |
if ( empty( $order ) ) { |
| 912 |
/** |
| 913 |
* Not having order_id |
| 914 |
*/ |
| 915 |
return ''; |
| 916 |
} |
| 917 |
|
| 918 |
$order_notes = $order->get_customer_order_notes(); |
| 919 |
$list_notes = ''; |
| 920 |
if ( ! empty( $order_notes ) && count( $order_notes ) > 0 ) { |
| 921 |
foreach ( $order_notes as $note ) { |
| 922 |
$list_notes .= wp_kses_post( wpautop( wptexturize( make_clickable( $note->comment_content ) ) ) ); |
| 923 |
} |
| 924 |
} |
| 925 |
return $list_notes; |
| 926 |
} |
| 927 |
|
| 928 |
public function yaymail_customer_provided_note( $data ) { |
| 929 |
$render_data = isset( $data['render_data'] ) ? $data['render_data'] : []; |
| 930 |
|
| 931 |
if ( ! empty( $render_data['is_sample'] ) ) { |
| 932 |
/** |
| 933 |
* Is sample order |
| 934 |
*/ |
| 935 |
return __( 'customer provided notes', 'yaymail' ); |
| 936 |
} |
| 937 |
|
| 938 |
$order = Helpers::get_order_from_shortcode_data( $render_data ); |
| 939 |
|
| 940 |
if ( empty( $order ) ) { |
| 941 |
/** |
| 942 |
* Not having order_id |
| 943 |
*/ |
| 944 |
return ''; |
| 945 |
} |
| 946 |
$customer_note = $order->get_customer_note(); |
| 947 |
if ( ! empty( $customer_note ) ) { |
| 948 |
return $customer_note; |
| 949 |
} |
| 950 |
return ''; |
| 951 |
} |
| 952 |
|
| 953 |
public function woocommerce_email_order_meta( $data ) { |
| 954 |
$render_data = isset( $data['render_data'] ) ? $data['render_data'] : []; |
| 955 |
|
| 956 |
if ( ! empty( $render_data['is_sample'] ) ) { |
| 957 |
/** |
| 958 |
* Is sample order |
| 959 |
*/ |
| 960 |
return '[woocommerce_email_order_meta]'; |
| 961 |
} |
| 962 |
|
| 963 |
$order = Helpers::get_order_from_shortcode_data( $render_data ); |
| 964 |
|
| 965 |
$email = $render_data['email'] ?? []; |
| 966 |
|
| 967 |
if ( empty( $order ) || empty( $email ) ) { |
| 968 |
/** |
| 969 |
* Not having order_id |
| 970 |
*/ |
| 971 |
return ''; |
| 972 |
} |
| 973 |
|
| 974 |
$sent_to_admin = isset( $render_data['sent_to_admin'] ) ? $render_data['sent_to_admin'] : false; |
| 975 |
$plain_text = isset( $render_data['plain_text'] ) ? $render_data['plain_text'] : false; |
| 976 |
|
| 977 |
ob_start(); |
| 978 |
|
| 979 |
do_action( 'woocommerce_email_order_meta', $order, $sent_to_admin, $plain_text, $email ); |
| 980 |
|
| 981 |
$return = ob_get_clean(); |
| 982 |
|
| 983 |
return $return; |
| 984 |
} |
| 985 |
} |
| 986 |
|