PluginProbe
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell / 2.8.16
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell v2.8.16
3.13.3 3.13.2 3.13.1 3.13.0 3.12.13 3.12.12 3.12.11 3.12.10 3.12.9 3.12.8 3.12.7 3.12.6 3.12.5 3.12.4 3.12.3 3.12.1 3.12.2 3.12.0 3.11.1 3.11.0 3.10.9 3.10.8 3.10.7 3.10.6 2.8.16 All 261 releases
wpfunnels / includes / core / shortcodes / class-wpfnl-shortcode-order-details.php

class-wpfnl-shortcode-order-details.php in WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell 2.8.16, at includes/core/shortcodes/class-wpfnl-shortcode-order-details.php

201 lines 5.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Order details shortcode class
4 *
5 * @package
6 */
7 namespace WPFunnels\Shortcodes;
8
9 use WPFunnels\Wpfnl_functions;
10
11 /**
12 * Class WC_Shortcode_Optin
13 *
14 * @package WPFunnels\Shortcodes
15 */
16 class Wpfnl_Shortcode_Order_details {
17
18 /**
19 * Attributes
20 *
21 * @var array
22 */
23 protected $attributes = array();
24
25
26 /**
27 * Wpfnl_Shortcode_Order_details constructor.
28 *
29 * @param array $attributes
30 */
31 public function __construct( $attributes = array() ) {
32 $this->attributes = $this->parse_attributes( $attributes );
33 }
34
35
36 /**
37 * Get shortcode attributes.
38 *
39 * @since 3.2.0
40 * @return array
41 */
42 public function get_attributes() {
43 return $this->attributes;
44 }
45
46
47 /**
48 * Parse attributes
49 *
50 * @param $attributes
51 *
52 * @return array
53 */
54 protected function parse_attributes( $attributes ) {
55 $attributes = shortcode_atts(
56 array(
57 'class' => '',
58 'child_order_class' => '',
59 ),
60 $attributes
61 );
62 return $attributes;
63 }
64
65
66 /**
67 * Get wrapper classes
68 *
69 * @return array
70 */
71 protected function get_wrapper_classes() {
72 $classes = array( 'wpfnl', 'wpfnl-order-details-wrapper' );
73 return $classes;
74 }
75
76
77 /**
78 * Content of optin form
79 *
80 * @return string
81 */
82 public function get_content() {
83 $output = '';
84 $show_dummy_order_details = false;
85
86 // allow to show the order details markup on preview
87 if ( is_admin() ) {
88 $show_dummy_order_details = apply_filters( 'wpfunnels/show_dummy_order_details', true );
89 }
90
91 if(Wpfnl_functions::is_elementor_active()) {
92 $elementor_preview_active = \Elementor\Plugin::$instance->preview->is_preview_mode();
93 if( $elementor_preview_active ) {
94 $show_dummy_order_details = apply_filters( 'wpfunnels/show_dummy_order_details', false );
95 }
96 }
97
98
99 if( Wpfnl_functions::check_if_this_is_step_type('thankyou') || $show_dummy_order_details ) {
100 add_filter( 'woocommerce_order_item_permalink', '__return_false' );
101
102 $order = false;
103
104 $id_param = 'wpfnl-order';
105 $key_param = 'wpfnl-key';
106 $child_orders = null;
107 if ( !isset($_GET[$id_param]) && $show_dummy_order_details ) {
108 $args = array(
109 'limit' => 1,
110 'order' => 'DESC',
111 'post_type' => 'shop_order',
112 'status' => array( 'completed', 'processing' ),
113 );
114
115 $latest_order = wc_get_orders( $args );
116
117 $order_id = ( ! empty( $latest_order ) ) ? current( $latest_order )->get_id() : 0;
118 if ( $order_id > 0 ) {
119 /**
120 * Fires when the page is the "Thank You" page.
121 *
122 * This hook allows you to perform actions specific to the "Thank You" page,
123 * typically triggered if there is at least one order created
124 *
125 * @param int $order_id The ID of the completed order.
126 * @since 2.0.0
127 */
128 do_action('wpfunnels/page_is_thankyou',$order_id);
129 $order = wc_get_order( $order_id );
130 if ( ! $order ) {
131 $order = false;
132 }
133 } else {
134 return '<p class="woocommerce-notice">' . __( 'No completed orders found in your shop for demo.', 'wpfnl' ) . '</p>';
135 }
136 }
137 else {
138
139 if (!isset($_GET[$id_param])) { //phpcs:ignore
140 return '<p class="woocommerce-notice">' . __( 'Order not found. You cannot access this page directly.', 'wpfnl' ) . '</p>';
141 }
142
143 $order_id = empty($_GET[$id_param]) ? 0 : intval($_GET[$id_param]);
144 $order_key = empty($_GET[$key_param]) ? '' : wc_clean(wp_unslash($_GET[$key_param]));
145
146 if ( $order_id > 0 ) {
147 /**
148 * Fires when the page is the "Thank You" page.
149 *
150 * This hook allows you to perform actions specific to the "Thank You" page,
151 * typically triggered if there is at least one order created
152 *
153 * @param int $order_id The ID of the completed order.
154 * @since 2.0.0
155 */
156 do_action('wpfunnels/page_is_thankyou',$order_id);
157 $order = wc_get_order( $order_id );
158
159 if (!Wpfnl_functions::is_valid_order_owner( $order )){
160 return '<p class="woocommerce-notice">' . __( 'You are not authorized to view the order details.', 'wpfnl' ) . '</p>';
161 }
162
163 $child_orders = get_post_meta($order_id, '_wpfnl_offer_child_orders', true);
164 if ( ! $order || $order->get_order_key() !== $order_key ) {
165 $order = false;
166 }
167 }
168 }
169 $class = isset($this->attributes['class']) ? esc_html($this->attributes['class']) : '';
170 $child_order_class = isset($this->attributes['child_order_class']) ? esc_html($this->attributes['child_order_class']) : '';
171 // Empty awaiting payment session.
172 unset( WC()->session->order_awaiting_payment );
173 ob_start();
174 echo "<div class='woocommerce'>";
175 echo "<div class='wpfnl-thankyou-wrapper ".$class."' id='wpfnl-thankyou-wrapper'>";
176 wc_get_template( 'checkout/thankyou.php',
177 array(
178 'order' => $order
179 )
180 );
181
182 if ( $child_orders ) {
183 echo "<div class='wpfnl-child-order-wrapper ".$child_order_class."' id='wpfnl-child-order-wrapper'>";
184 foreach ( $child_orders as $order_id => $value) {
185 wc_get_template( 'checkout/thankyou.php',
186 array(
187 'order' => $order
188 )
189 );
190 }
191 echo '</div>';
192 }
193 echo '</div>';
194 echo '</div>';
195 $output = ob_get_clean();
196 }
197
198 return $output;
199 }
200 }
201