PluginProbe
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell / 3.13.1
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell v3.13.1
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 3.13.1, at includes/core/shortcodes/class-wpfnl-shortcode-order-details.php

220 lines 5.9 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 'step_id' => '',
60 ),
61 $attributes
62 );
63 return $attributes;
64 }
65
66
67 /**
68 * Get wrapper classes
69 *
70 * @return array
71 */
72 protected function get_wrapper_classes() {
73 $classes = array( 'wpfnl', 'wpfnl-order-details-wrapper' );
74 return $classes;
75 }
76
77
78 /**
79 * Content of optin form
80 *
81 * @return string
82 */
83 public function get_content() {
84 $output = '';
85
86 // Default: enable demo mode in admin and REST (Divi VB) contexts.
87 // Callers can override via the filter (e.g. Elementor forces false below).
88 $in_preview_context = is_admin() || ( defined( 'REST_REQUEST' ) && REST_REQUEST );
89 $show_dummy_order_details = (bool) apply_filters(
90 'wpfunnels/show_dummy_order_details',
91 $in_preview_context
92 );
93
94 if(Wpfnl_functions::is_elementor_active()) {
95 $elementor_preview_active = \Elementor\Plugin::$instance->preview->is_preview_mode();
96 if( $elementor_preview_active ) {
97 $show_dummy_order_details = apply_filters( 'wpfunnels/show_dummy_order_details', false );
98 }
99 }
100
101 $is_funnel_step = $this->attributes['step_id'] ? Wpfnl_functions::maybe_funnel_step( $this->attributes['step_id'] ) : false;
102
103 if( Wpfnl_functions::is_wc_active() && Wpfnl_functions::check_if_this_is_step_type('thankyou') || $show_dummy_order_details || $is_funnel_step ) {
104 add_filter( 'woocommerce_order_item_permalink', '__return_false' );
105
106 $order = false;
107
108 $id_param = 'wpfnl-order';
109 $key_param = 'wpfnl-key';
110 $child_orders = null;
111 if ( !isset($_GET[$id_param]) && $show_dummy_order_details ) {
112 // Try completed/processing first, then fall back to any order.
113 $latest_order = wc_get_orders( array(
114 'limit' => 1,
115 'order' => 'DESC',
116 'status' => array( 'completed', 'processing' ),
117 ) );
118
119 if ( empty( $latest_order ) ) {
120 $latest_order = wc_get_orders( array(
121 'limit' => 1,
122 'order' => 'DESC',
123 ) );
124 }
125
126 $order_id = ( ! empty( $latest_order ) ) ? current( $latest_order )->get_id() : 0;
127 if ( $order_id > 0 ) {
128 /**
129 * Fires when the page is the "Thank You" page.
130 *
131 * This hook allows you to perform actions specific to the "Thank You" page,
132 * typically triggered if there is at least one order created
133 *
134 * @param int $order_id The ID of the completed order.
135 * @since 2.0.0
136 */
137 do_action('wpfunnels/page_is_thankyou',$order_id);
138 $order = wc_get_order( $order_id );
139 if ( ! $order ) {
140 $order = false;
141 }
142 } else {
143 // No orders in the shop — show a static placeholder so the
144 // widget still renders something useful in the builder.
145 return '<div class="woocommerce wpfnl-order-details-placeholder">'
146 . '<p class="woocommerce-notice">'
147 . __( 'Order details will appear here after a customer completes checkout.', 'wpfnl' )
148 . '</p>'
149 . '</div>';
150 }
151 }
152 else {
153
154 if (!isset($_GET[$id_param])) { //phpcs:ignore
155 return '<p class="woocommerce-notice">' . __( 'Order not found. You cannot access this page directly.', 'wpfnl' ) . '</p>';
156 }
157
158 $order_id = empty($_GET[$id_param]) ? 0 : intval($_GET[$id_param]);
159 $order_key = empty($_GET[$key_param]) ? '' : wc_clean(wp_unslash($_GET[$key_param]));
160
161 if ( $order_id > 0 ) {
162 /**
163 * Fires when the page is the "Thank You" page.
164 *
165 * This hook allows you to perform actions specific to the "Thank You" page,
166 * typically triggered if there is at least one order created
167 *
168 * @param int $order_id The ID of the completed order.
169 * @since 2.0.0
170 */
171 do_action('wpfunnels/page_is_thankyou',$order_id);
172 $order = wc_get_order( $order_id );
173
174 if (!Wpfnl_functions::is_valid_order_owner( $order, $order_key )){
175 return '<p class="woocommerce-notice">' . __( 'You are not authorized to view the order details.', 'wpfnl' ) . '</p>';
176 }
177
178 $child_orders = get_post_meta($order_id, '_wpfnl_offer_child_orders', true);
179 if ( ! $order || $order->get_order_key() !== $order_key ) {
180 $order = false;
181 }
182 }
183 }
184
185 if( is_a( $order, 'WC_Order' ) ) {
186 $class = isset($this->attributes['class']) ? esc_html($this->attributes['class']) : '';
187 $child_order_class = isset($this->attributes['child_order_class']) ? esc_html($this->attributes['child_order_class']) : '';
188 // Empty awaiting payment session.
189 unset( WC()->session->order_awaiting_payment );
190 ob_start();
191 echo "<div class='woocommerce'>";
192 echo "<div class='wpfnl-thankyou-wrapper ".$class."' id='wpfnl-thankyou-wrapper'>";
193 wc_get_template( 'checkout/thankyou.php',
194 array(
195 'order' => $order
196 )
197 );
198 }
199
200
201 if ( $child_orders ) {
202 echo "<div class='wpfnl-child-order-wrapper ".$child_order_class."' id='wpfnl-child-order-wrapper'>";
203 foreach ( $child_orders as $order_id => $value) {
204 wc_get_template( 'checkout/thankyou.php',
205 array(
206 'order' => $order
207 )
208 );
209 }
210 echo '</div>';
211 }
212 echo '</div>';
213 echo '</div>';
214 $output = ob_get_clean();
215 }
216
217 return $output;
218 }
219 }
220