PluginProbe
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster / 2.3.0
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster v2.3.0
2.7.0 2.6.0 trunk 1.1.0 1.1.4 1.2.1 1.2.2 1.2.3 1.2.5 1.2.9 1.3.1 1.3.2 1.5.0 1.5.1 1.5.4 1.5.7 1.5.8 1.5.9 1.6.2 1.6.5 1.6.8 1.7.2 1.7.4 1.7.5 1.7.9 All 43 releases
sellkit / includes / dynamic-keywords / keywords / coupon-expiry-date.php

coupon-expiry-date.php in SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster 2.3.0, at includes/dynamic-keywords/keywords/coupon-expiry-date.php

84 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class Coupon_Expiry_Date extends Tag_Base {
4 /**
5 * Get class id.
6 *
7 * @return string
8 */
9 public function get_id() {
10 return '_coupon_expiry_date';
11 }
12
13 /**
14 * Get class title.
15 *
16 * @return string
17 */
18 public function get_title() {
19 return esc_html__( 'Coupon Expiry Date', 'sellkit' );
20 }
21
22 /**
23 * Render true content.
24 *
25 * @param array $atts array of shortcode arguments.
26 * @return string
27 */
28 public function render_content( $atts ) {
29 $this->get_data();
30
31 if ( empty( self::$order ) ) {
32 return $this->shortcode_content( $atts );
33 }
34
35 $order_data = $this->get_coupon_expire_date_data( self::$order );
36
37 if ( empty( $order_data ) ) {
38 return $this->shortcode_content( $atts );
39 }
40
41 return $order_data;
42 }
43
44 /**
45 * Get coupon expire date data.
46 *
47 * @since 1.1.0
48 * @param object $order object of order parameters.
49 * @return array
50 */
51 public function get_coupon_expire_date_data( $order ) {
52 if ( empty( $order->get_items( 'coupon' ) ) ) {
53 return;
54 }
55
56 $order_data = '';
57
58 foreach ( $order->get_items( 'coupon' ) as $coupon_id => $coupon ) {
59 $query_args = [
60 'post_type' => 'shop_coupon',
61 'post_title' => $coupon->get_name(),
62 'posts_per_page' => 1,
63 ];
64
65 $coupons_query = new WP_Query( $query_args );
66 $current_coupon_obj = (object) $coupons_query->get_posts()[0];
67 $current_coupon_id = $current_coupon_obj->ID;
68 $current_coupon = new WC_Coupon( $current_coupon_id );
69
70 if ( empty( $current_coupon->get_date_expires() ) ) {
71 continue;
72 }
73
74 $order_data = $current_coupon->get_date_expires()->date( 'Y-m-d H:i:s' );
75 }
76
77 if ( empty( $order_data ) ) {
78 return;
79 }
80
81 return $order_data;
82 }
83 }
84