PluginProbe
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant / 1.9.1
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant v1.9.1
2.3.2 2.3.1 2.3.0 2.2.8 2.2.7 trunk 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.10.5 1.11.0 1.11.1 1.11.2 1.6 1.7 1.8 1.8.1 1.8.2 1.8.3 1.9.0 1.9.1 1.9.10 1.9.11 All 60 releases
merchant / inc / modules / pre-orders / class-pre-orders-main-functionality.php

class-pre-orders-main-functionality.php in Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant 1.9.1, at inc/modules/pre-orders/class-pre-orders-main-functionality.php

660 lines 21.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Pre Orders.
5 *
6 * @package Merchant
7 */
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit; // Exit if accessed directly
11 }
12
13 /**
14 * Pre Orders Class.
15 *
16 */
17 class Merchant_Pre_Orders_Main_Functionality {
18
19 /**
20 * Pre order products.
21 *
22 */
23 private $pre_order_products = array();
24
25 /**
26 * Flag if the_title filter is added or not.
27 *
28 * @var bool
29 */
30 private $is_pre_order_filter_on = false;
31
32 /**
33 * Init.
34 *
35 * @return void
36 */
37 public function init() {
38 add_filter( 'woocommerce_add_to_cart_validation', array( $this, 'allow_one_type_only' ), 99, 2 );
39
40 add_action( 'woocommerce_checkout_update_order_meta', array( $this, 'manage_pre_orders' ), 10, 2 );
41 add_filter( 'woocommerce_thankyou', array( $this, 'set_pre_order_status' ), 10 );
42 add_filter( 'woocommerce_billing_fields', array( $this, 'add_shipping_date_field' ) );
43
44 // Cronjob.
45 if ( ! wp_next_scheduled( 'check_for_released_preorders' ) ) {
46 wp_schedule_event( time(), 'twicedaily', 'check_for_released_preorders' );
47 }
48
49 add_action( 'check_for_released_preorders', array( $this, 'check_for_pre_orders_and_maybe_update_status' ) );
50
51 // Variations tab
52 add_action( 'woocommerce_product_after_variable_attributes', array( $this, 'custom_fields_for_variable_products' ), 10, 3 );
53
54 // Inventory tab
55 add_action( 'woocommerce_product_options_stock_status', array( $this, 'custom_fields_for_simple_products' ) );
56
57 add_action( 'woocommerce_save_product_variation', array( $this, 'custom_fields_for_variable_products_save' ), 10, 2 );
58 add_action( 'woocommerce_process_product_meta', array( $this, 'custom_fields_for_simple_products_save' ), 10, 2 );
59
60 add_filter( 'woocommerce_product_add_to_cart_text', array( $this, 'change_button_text' ), 10, 2 );
61 add_filter( 'woocommerce_product_single_add_to_cart_text', array( $this, 'change_button_text' ), 10, 2 );
62 add_filter( 'woocommerce_available_variation', array( $this, 'change_button_text_for_variable_products' ), 10, 3 );
63 add_action( 'woocommerce_before_add_to_cart_form', array( $this, 'maybe_render_additional_information' ), 10 );
64
65 // Cart
66 add_filter( 'woocommerce_get_item_data', array( $this, 'cart_message_handler' ), 10, 2 );
67
68 add_action( 'woocommerce_order_item_meta_end', array( $this, 'order_item_meta_end' ), 10, 4 );
69 add_action( 'woocommerce_shop_loop_item_title', array( $this, 'shop_loop_item_title' ) );
70
71 // Products block.
72 add_filter( 'render_block_context', array( $this, 'add_block_title_filter' ), 10, 1 );
73 add_filter( 'woocommerce_blocks_product_grid_item_html', array( $this, 'override_product_grid_block' ), PHP_INT_MAX, 3 );
74
75 $this->register_pre_orders_order_status();
76 add_filter( 'wc_order_statuses', array( $this, 'add_pre_orders_order_statuses' ) );
77 add_filter( 'woocommerce_post_class', array( $this, 'pre_orders_post_class' ), 10, 3 );
78 }
79
80 /**
81 * Validation (one type only).
82 *
83 * @param boolean $passed
84 * @param integer $product_id
85 * @return boolean
86 */
87 public function allow_one_type_only( $passed, $product_id ) {
88 $products = array_filter( WC()->cart->get_cart_contents() );
89 $has_pre_orders = false;
90
91 foreach ( $products as $product ) {
92 $is_pre_order = $this->is_pre_order( $product['data']->get_id() );
93 if ( $is_pre_order ) {
94 $has_pre_orders = true;
95 }
96 }
97
98 $input_post_data = array(
99 'variation_id' => filter_input(INPUT_POST, 'variation_id', FILTER_SANITIZE_NUMBER_INT),
100 );
101
102 $variable_id = ( isset( $input_post_data['variation_id'] ) ) ? sanitize_text_field( wp_unslash( $input_post_data['variation_id'] ) ) : 0;
103 $is_variable_has_pre_order = $this->is_pre_order( $product_id ) || $this->is_pre_order( $variable_id );
104
105 if ( empty( $products ) || ( $is_variable_has_pre_order && $has_pre_orders ) || ( false === $is_variable_has_pre_order && false === $has_pre_orders ) ) {
106 $passed = true;
107 } else {
108 $passed = false;
109 if ( $is_variable_has_pre_order ) {
110 $notice = esc_html__( 'We detected that you are trying to add a pre-order product in your cart. Please remove the rest of the products before proceeding.', 'merchant' );
111 } else {
112 $notice = esc_html__( 'We detected that your cart has pre-order products. Please remove them before being able to add this product.', 'merchant' );
113 }
114 wc_add_notice( $notice, 'error' );
115 }
116
117 return $passed;
118 }
119
120 /**
121 * Check if product is a pre order item by product ID.
122 *
123 * @param integer $product_id
124 * @return boolean
125 */
126 public function is_pre_order( $product_id ) {
127 return 'yes' === get_post_meta( $product_id, '_is_pre_order', true ) && strtotime( get_post_meta( $product_id, '_pre_order_date', true ) ) > time();
128 }
129
130 /**
131 * Update pre order meta data (date).
132 *
133 * @param integer $orderId
134 * @param array $data
135 * @return void
136 */
137 public function manage_pre_orders( $orderId, $data ) {
138 $order = wc_get_order( $orderId );
139
140 if ( isset( $data['preorder_date'] ) ) {
141 $order->update_meta_data( '_preorder_date', esc_attr( $data['preorder_date'] ) );
142 $order->save();
143 }
144 }
145
146 /**
147 * Set pre order status.
148 *
149 * @param string $status
150 * @param integer $order_id
151 * @param object $order
152 * @return string
153 */
154 public function set_pre_order_status( $order_id ) {
155 if ( ! $order_id ) {
156 return;
157 }
158
159 $order = wc_get_order($order_id);
160
161 // Change the order status.
162 if ( $order->get_meta( '_preorder_date' ) ) {
163 $order->update_status( 'wc-pre-ordered' );
164 }
165
166 // Save.
167 $order->save();
168 }
169
170 /**
171 * Add shipping date field.
172 *
173 * @param array $fields
174 * @return array
175 */
176 public function add_shipping_date_field( $fields ) {
177 if ( ! is_checkout() && ! is_cart() ) {
178 return $fields;
179 }
180
181 global $woocommerce;
182
183 $this->check_pre_order_products( $woocommerce->cart->get_cart() );
184
185 if ( count( $this->get_pre_order_products() ) > 0 ) {
186 $fields['preorder_date'] = array(
187 'type' => 'text',
188 'class' => array( 'merchant-hidden' ),
189 'required' => true,
190 'default' => $this->get_oldest_date(),
191 );
192 }
193
194 return $fields;
195 }
196
197 /**
198 * Check pre order products in cart.
199 *
200 * @param array $items
201 * @return void
202 */
203 public function check_pre_order_products( $items ) {
204 if ( isset( $items['line_items'] ) ) {
205 $items = $items['line_items'];
206 }
207
208 $pre_order_products = array_filter( $items, function ( $v ) {
209 return $this->is_pre_order( $v['product_id'] ) || $this->is_pre_order( $v['variation_id'] );
210 } );
211
212 $this->set_pre_order_products( $pre_order_products );
213 }
214
215 /**
216 * Get the oldest date.
217 *
218 * @return string
219 */
220 public function get_oldest_date() {
221 $product_with_oldest_date = array_reduce( $this->get_pre_order_products(), function ( $a, $b ) {
222 if ( null === $a ) {
223 return $b;
224 }
225 $aId = isset( $a['variation_id'] ) && 0 !== $a['variation_id'] ? $a['variation_id'] : $a['product_id'];
226 $bId = isset( $b['variation_id'] ) && 0 !== $b['variation_id'] ? $b['variation_id'] : $b['product_id'];
227 return $a ? ( strtotime( get_post_meta( $aId, '_pre_order_date', true ) ) > strtotime( get_post_meta( $bId, '_pre_order_date', true ) ) ? $a : $b ) : $b;
228 } );
229
230 $oldestId = isset( $product_with_oldest_date['variation_id'] ) && 0 !== $product_with_oldest_date['variation_id'] ? $product_with_oldest_date['variation_id'] : $product_with_oldest_date['product_id'];
231
232 return get_post_meta( $oldestId, '_pre_order_date', true );
233 }
234
235 /**
236 * Get pre order products.
237 *
238 * @return array
239 */
240 public function get_pre_order_products() {
241 return $this->pre_order_products;
242 }
243
244 /**
245 * Set pre order products.
246 *
247 * @param array $pre_order_products
248 * @return $this
249 */
250 public function set_pre_order_products( $pre_order_products ) {
251 $this->pre_order_products = $pre_order_products;
252 return $this;
253 }
254
255 /**
256 * Check for pre orders and maybe update the status.
257 *
258 * @return void
259 */
260 public function check_for_pre_orders_and_maybe_update_status() {
261 $args = array(
262 'status' => 'wc-pre-ordered',
263 );
264
265 $pre_ordered_orders = wc_get_orders( $args );
266
267 foreach ( $pre_ordered_orders as $order ) {
268 $pre_order_date = strtotime( $order->get_meta('_preorder_date') );
269
270 if ( $pre_order_date < time() ) {
271 $parent_order_id = $order->get_parent_id();
272
273 if ( 0 !== $parent_order_id ) {
274 $parent_order = wc_get_order( $parent_order_id );
275
276 if ( $parent_order->get_status() === 'completed' ) {
277 $order->update_status( 'wc-completed', '[WooCommerce Pre Orders] ' );
278 }
279 } elseif ( $order->get_status() === 'wc-pre-ordered' && $order->payment_complete() ) {
280 $order->update_status( 'wc-completed', '[WooCommerce Pre Orders] ' );
281 }
282 }
283 }
284 }
285
286 /**
287 * Custom pre-order fields for variations.
288 *
289 * @param integer $loop
290 * @param array $variation_data
291 * @param object $variation
292 * @return void
293 */
294 public function custom_fields_for_variable_products( $loop, $variation_data, $variation ) {
295 echo '<div class="is_pre_order_meta_field form-row form-row-full" style="display: flex; align-items: center;">';
296 woocommerce_wp_checkbox(
297 array(
298 'id' => '_is_pre_order_' . $variation->ID,
299 'label' => '&nbsp;' . esc_html__( 'Pre-Order Product - Set this product as pre-order', 'merchant' ),
300 'value' => get_post_meta( $variation->ID, '_is_pre_order', true ),
301 )
302 );
303
304 echo wc_help_tip( __( 'Important: To pre-order out of stock products you must enable the \'Backorder\' stock option.', 'merchant' ) );
305 echo '</div>';
306 echo '<div class="form-row form-row-full">';
307 woocommerce_wp_text_input(
308 array(
309 'type' => 'date',
310 'id' => '_pre_order_date_' . $variation->ID,
311 'label' => esc_html__( 'Pre-Order Shipping Date', 'merchant' ),
312 'value' => get_post_meta( $variation->ID, '_pre_order_date', true ),
313 )
314 );
315 echo '</div>';
316 }
317
318 /**
319 * Custom pre-order fields for simple products.
320 *
321 * @return void
322 */
323 public function custom_fields_for_simple_products() {
324 echo '<div class="is_pre_order_meta_field form-row form-row-full hide_if_variable" style="display: flex; align-items: center;">';
325 woocommerce_wp_checkbox(
326 array(
327 'id' => '_is_pre_order',
328 'label' => esc_html__( 'Pre-Order Product', 'merchant' ),
329 'description' => esc_html__( 'Set this product as pre-order', 'merchant' ),
330 'value' => get_post_meta( get_the_ID(), '_is_pre_order', true ),
331 )
332 );
333
334 echo '<div style="margin-left: -20px">';
335 echo wc_help_tip( __( 'Important: To pre-order out of stock products you must enable the \'Backorder\' stock option.', 'merchant' ) );
336 echo '</div>';
337 echo '</div>';
338 echo '<div class="form-row form-row-full hide_if_variable">';
339 woocommerce_wp_text_input(
340 array(
341 'type' => 'date',
342 'id' => '_pre_order_date',
343 'label' => esc_html__( 'Pre-Order Shipping Date', 'merchant' ),
344 'value' => get_post_meta( get_the_ID(), '_pre_order_date', true ),
345 )
346 );
347 echo '</div>';
348 }
349
350 /**
351 * Save custom fields for variable products.
352 *
353 * @param integer $post_id
354 * @return void
355 */
356 public function custom_fields_for_variable_products_save( $post_id ) {
357 $input_post_data = array(
358 '_is_pre_order_by_post_id' => filter_input(INPUT_POST, '_is_pre_order_' . $post_id, FILTER_SANITIZE_FULL_SPECIAL_CHARS),
359 '_pre_order_data_by_post_id' => filter_input(INPUT_POST, '_pre_order_date_' . $post_id, FILTER_SANITIZE_FULL_SPECIAL_CHARS),
360 );
361
362 $product = wc_get_product( $post_id );
363
364 $is_pre_order_variation = isset( $input_post_data[ '_is_pre_order_by_post_id' ] ) ? 'yes' : 'no';
365 $product->update_meta_data( '_is_pre_order', $is_pre_order_variation );
366
367 if ( 'yes' === $is_pre_order_variation && isset( $input_post_data[ '_pre_order_data_by_post_id' ] ) ) {
368 $pre_order_date_value = sanitize_text_field( wp_unslash( $input_post_data[ '_pre_order_data_by_post_id' ] ) );
369 $product->update_meta_data( '_pre_order_date', $pre_order_date_value );
370 }
371
372 $product->save();
373 }
374
375 /**
376 * Save custom fields for simple products.
377 *
378 * @param integer $post_id
379 * @return void
380 */
381 public function custom_fields_for_simple_products_save( $post_id ) {
382 $input_post_data = array(
383 '_is_pre_order' => filter_input(INPUT_POST, '_is_pre_order', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
384 '_pre_order_date' => filter_input(INPUT_POST, '_pre_order_date', FILTER_SANITIZE_FULL_SPECIAL_CHARS),
385 );
386
387 $product = wc_get_product( $post_id );
388 $is_pre_order = isset( $input_post_data['_is_pre_order'] ) ? 'yes' : 'no';
389 $product->update_meta_data( '_is_pre_order', $is_pre_order );
390
391 if ( 'yes' === $is_pre_order && isset( $input_post_data['_pre_order_date'] ) ) {
392 $pre_order_date_value = sanitize_text_field( wp_unslash( $input_post_data['_pre_order_date'] ) );
393 $product->update_meta_data( '_pre_order_date', esc_attr( $pre_order_date_value ) );
394 } else {
395 $product->update_meta_data( '_pre_order_date', '' );
396 }
397
398 $product->save();
399 }
400
401 /**
402 * Change pre-order button text.
403 *
404 * @param string $text
405 * @param WC_Product $product
406 * @return string
407 */
408 public function change_button_text( $text, $product ) {
409 if ( $product && $this->is_pre_order( $product->get_id() ) ) {
410 $text = Merchant_Admin_Options::get( 'pre-orders', 'button_text', esc_html__( 'Pre Order Now!', 'merchant' ) );
411 }
412
413 return $text;
414 }
415
416 /**
417 * Change pre-order button text for variable products.
418 *
419 * @param array $data
420 * @param object $product
421 * @param object $variation
422 * @return array
423 */
424 public function change_button_text_for_variable_products( $data, $product, $variation ) {
425 global $product;
426
427 if ( $this->is_pre_order( $variation->get_id() ) ) {
428
429 $data['is_pre_order'] = true;
430
431 $additional_text = Merchant_Admin_Options::get( 'pre-orders', 'additional_text', esc_html__( 'Ships on {date}.', 'merchant' ) );
432 $time_format = date_i18n( get_option( 'date_format' ), strtotime( get_post_meta( $variation->get_id(), '_pre_order_date', true ) ) );
433 $text = $this->replaceDateTxt( $additional_text, $time_format );
434
435 if ( ! empty( $text ) ) {
436 $data['is_pre_order_date'] = $this->replaceDateTxt( $additional_text, $time_format );
437 }
438
439 }
440
441 return $data;
442 }
443
444 /**
445 * Replace {date} markup with new text.
446 *
447 * @param string $string_contains_date_tag
448 * @param string $time_format
449 *
450 * @return string
451 */
452 public function replaceDateTxt( $string_contains_date_tag, $time_format ) {
453 $from = array( '{date}' );
454 $to = array( $time_format );
455
456 return str_replace( $from, $to, $string_contains_date_tag );
457 }
458
459 /**
460 * Maybe render additional information.
461 *
462 * @return void
463 */
464 public function maybe_render_additional_information() {
465 $input_post_data = array(
466 'product_id' => filter_input(INPUT_POST, 'product_id', FILTER_SANITIZE_NUMBER_INT),
467 );
468
469 global $post, $product;
470
471 // Do not override globals.
472 $_post = $post;
473 $_product = $product;
474
475 // In some cases the $post might be null. e.g inside quick view popup.
476 if ( ! $_post && isset( $input_post_data[ 'product_id' ] ) ) {
477 $_post = get_post( absint( $input_post_data[ 'product_id' ] ) );
478 $_product = wc_get_product( $_post->ID );
479 }
480
481 if ( null !== $_product ) {
482 if ( $this->is_pre_order( $_post->ID ) ) {
483 $additional_text = Merchant_Admin_Options::get( 'pre-orders', 'additional_text', esc_html__( 'Ships on {date}.', 'merchant' ) );
484 $time_format = date_i18n( get_option( 'date_format' ), strtotime( get_post_meta( $_post->ID, '_pre_order_date', true ) ) );
485 $text = $this->replaceDateTxt( $additional_text, $time_format );
486
487 printf( '<div class="merchant-pre-orders-date">%s</div>', esc_html( $text ) );
488 }
489 }
490 }
491
492 /**
493 * Register pre orders status.
494 *
495 * @return void
496 */
497 public function register_pre_orders_order_status() {
498 register_post_status( 'wc-pre-ordered', array(
499 'label' => esc_html__( 'Pre Ordered', 'merchant' ),
500 'public' => true,
501 'show_in_admin_status_list' => true,
502 'show_in_admin_all_list' => true,
503 'exclude_from_search' => false,
504 /* translators: %s: pre ordered product count */
505 'label_count' => _n_noop( 'Pre Ordered <span class="count">(%s)</span>', 'Pre Ordered <span class="count">(%s)</span>', 'merchant' ),
506 ) );
507 }
508
509 /**
510 * Add pre orders status to order statuses.
511 *
512 * @param array $order_statuses
513 * @return array
514 */
515 public function add_pre_orders_order_statuses( $order_statuses ) {
516 $order_statuses['wc-pre-ordered'] = 'Pre Ordered';
517
518 return $order_statuses;
519 }
520
521 /**
522 * Add pre orders class identifies to the body tag.
523 *
524 */
525 public function pre_orders_post_class( $classes, $product ) {
526 if ( $this->is_pre_order( $product->get_id() ) ) {
527 $classes[] = 'merchant-pre-ordered-product';
528 }
529
530 return $classes;
531 }
532
533 /**
534 * Filters cart item data to display cart.
535 *
536 * @param array $item_data Cart item data.
537 * @param array $cart_item Cart item array.
538 *
539 * @return array
540 *
541 * @see wc_get_formatted_cart_item_data for filter usage.
542 */
543 public function cart_message_handler( $item_data, $cart_item ) {
544 $product_id = $cart_item['product_id'];
545 if ( $this->is_pre_order( $product_id ) ) {
546 $label_text = Merchant_Admin_Options::get( 'pre-orders', 'cart_label_text', esc_html__( 'Ships on', 'merchant' ) );
547 $pre_order_date = date_i18n( get_option( 'date_format' ), strtotime( get_post_meta( $product_id, '_pre_order_date', true ) ) );
548
549 $item_data[] = array(
550 'key' => $label_text,
551 'value' => $pre_order_date,
552 'display' => '',
553 );
554 }
555
556 return $item_data;
557 }
558
559 /**
560 * filter name: woocommerce_order_item_meta_end
561 * Adds pre order additional text to the order item name
562 *
563 * @param int $item_id Product ID.
564 * @param \WC_Order_Item_Product $item Item array data.
565 * @param \WC_Order $order Order data.
566 * @param bool $plain_text Is plain text or not.
567 * @return string
568 */
569 public function order_item_meta_end( $item_id, $item, $order, $plain_text ) {
570 echo $this->get_pre_order_text( $item->get_product()->get_id(), $plain_text ? '' : 'dl' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
571 }
572
573 /**
574 * Render pre order text.
575 */
576 public function shop_loop_item_title() {
577 echo $this->get_pre_order_text( get_the_ID(), 'span' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
578 }
579
580 /**
581 * Add the_title filter for block rendering.
582 * @param array $context Default context.
583 * @return array
584 */
585 public function add_block_title_filter( $context ) {
586 if ( ! empty( $context['postType'] ) && 'product' === $context['postType'] && ! $this->is_pre_order_filter_on ) {
587 $this->is_pre_order_filter_on = true;
588 add_filter( 'the_title', array( $this, 'block_add_the_title_filter' ), 10, 2 );
589 add_filter( 'render_block', array( $this, 'block_remove_the_title_filter' ), 10, 3 );
590 }
591 return $context;
592 }
593
594 /**
595 * Add pre order info to product grid block.
596 *
597 * @param string $html Product grid item HTML.
598 * @param object $data Product data passed to the template.
599 * @param \WC_Product $product Product object.
600 * @return string Updated product grid item HTML.
601 */
602 public function override_product_grid_block( $html, $data, $product ) {
603 $pre_order_text = $this->get_pre_order_text( $product->get_id(), 'span' );
604 if ( $pre_order_text ) {
605 $html = str_replace( $data->title, $data->title . $pre_order_text, $html );
606 }
607 return $html;
608 }
609
610 /**
611 * Adds pre order info to post_title.
612 *
613 * @param string $title Title.
614 * @param int $post_id Post ID.
615 * @return string
616 */
617 public function block_add_the_title_filter( $title, $post_id ) {
618 return $title . $this->get_pre_order_text( $post_id, 'span' );
619 }
620
621 /**
622 * Remove the_title filter when block rendering finished.
623 *
624 * @param string $block_content The block content.
625 * @param array $parsed_block The full block, including name and attributes.
626 * @param WP_Block $block The block instance.
627 *
628 * @return string
629 */
630 public function block_remove_the_title_filter( $block_content, $parsed_block, $block ) {
631 if ( $this->is_pre_order_filter_on ) {
632 remove_filter( 'the_title', array( $this, 'block_add_the_title_filter' ), 10 );
633 $this->is_pre_order_filter_on = false;
634 }
635 return $block_content;
636 }
637
638 /**
639 * Get pre order text by product ID.
640 *
641 * @param int $product_id
642 * @param string $render_type Render template type string. 'span', 'dl', ''. Default ''.
643 * @return string
644 */
645 private function get_pre_order_text( $product_id, $render_type = '' ) {
646 if ( ! $this->is_pre_order( $product_id ) ) {
647 return '';
648 }
649
650 $label_text = Merchant_Admin_Options::get( 'pre-orders', 'cart_label_text', __( 'Ships on', 'merchant' ) );
651 $pre_order_date = date_i18n( get_option( 'date_format' ), strtotime( get_post_meta( $product_id, '_pre_order_date', true ) ) );
652 if ( 'span' === $render_type ) {
653 return sprintf( '<span class="merchant-pre-orders-note"><span class="merchant-pre-orders-label">%s:</span><span>%s</span></span>', esc_html( $label_text ), $pre_order_date );
654 } elseif ( 'dl' === $render_type ) {
655 return sprintf( '<dl class="merchant-pre-orders-note"><dt>%s:</dt><dd>%s</dd></dl>', esc_html( $label_text ), $pre_order_date );
656 } else {
657 return sprintf( '%s: %s', esc_html( $label_text ), $pre_order_date );
658 }
659 }
660 }