PluginProbe
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell / 3.13.3
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell v3.13.3
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 / compatibility / plugin / class-wpfnl-woocommerce-germanized.php

class-wpfnl-woocommerce-germanized.php in WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell 3.13.3, at includes/core/compatibility/plugin/class-wpfnl-woocommerce-germanized.php

171 lines 6.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * WooCommerce Germanized Compatibility
4 *
5 * Handles two integration points between WPFunnels and Germanized:
6 *
7 * 1. Checkout submit button – Germanized hides the default WC submit button via
8 * woocommerce_order_button_html filter and renders its own block at the end
9 * of woocommerce_checkout_order_review. On WPFunnels funnel checkout pages
10 * this means the button lands outside WPFunnels' payment section. We tell
11 * Germanized to disable its checkout adjustments by defining the
12 * WC_GZD_DISABLE_CHECKOUT_ADJUSTMENTS constant before Germanized's own
13 * mechanism reads it (woocommerce_before_checkout_form priority -999).
14 * Germanized then:
15 * - stops hiding / relocating the WC order button,
16 * - moves legal checkboxes to woocommerce_review_order_before_payment
17 * so they still render inside WPFunnels' payment section, and
18 * - outputs a wc_gzd_checkout_disabled hidden field so AJAX order-review
19 * requests also carry the disabled flag.
20 *
21 * 2. Offer order confirmation – Germanized removes the standard WC order-
22 * notification hooks and sends its own confirmation via the
23 * woocommerce_payment_successful_result filter, which never fires for
24 * WPFunnels' AJAX offer acceptance. We hook into wpfunnels/offer_accepted
25 * and call Germanized's confirm_order() directly for child/separate orders.
26 *
27 * @package WPFunnels\Compatibility\Plugin
28 */
29 namespace WPFunnels\Compatibility\Plugin;
30
31 use WPFunnels\Traits\SingletonTrait;
32 use WPFunnels\Wpfnl_functions;
33
34 class WooCommerceGermanized extends PluginCompatibility {
35 use SingletonTrait;
36
37 /**
38 * Register hooks.
39 *
40 * @return void
41 */
42 public function init() {
43 // Disable Germanized's checkout adjustments on WPFunnels funnel checkout
44 // pages. Priority -1000 fires before Germanized's priority -999 handler
45 // (wc_gzd_maybe_disable_checkout_adjustments), so the constant is already
46 // set when Germanized reads it and removes its button/submit hooks.
47 add_action( 'woocommerce_before_checkout_form', array( $this, 'maybe_disable_checkout_adjustments' ), -1000 );
48
49 // Re-add the standard order-review/payment hooks that Germanized's ET Builder
50 // (Divi) compatibility strips when checkout adjustments are disabled. Priority 20
51 // runs after Germanized's own priority-10 handler so it can undo the removal.
52 add_action( 'woocommerce_gzd_disabled_checkout_adjustments', array( $this, 'restore_order_review_hooks' ), 20 );
53
54 // Trigger Germanized's order confirmation for upsell/downsell child orders.
55 add_action( 'wpfunnels/offer_accepted', array( $this, 'send_offer_order_confirmation' ), 10, 2 );
56 }
57
58 /**
59 * Restore the default WooCommerce order-review hooks on WPFunnels checkout steps.
60 *
61 * When the Divi theme is active, Germanized's ET Builder compatibility
62 * (WC_GZD_Compatibility_ET_Builder) listens on woocommerce_gzd_disabled_checkout_adjustments
63 * and removes woocommerce_order_review (priority 10) and woocommerce_checkout_payment
64 * (priority 20) from woocommerce_checkout_order_review. It assumes Divi's own native
65 * checkout modules (et_pb_wc_checkout_order_details / _payment_info) will re-add them.
66 *
67 * WPFunnels' Divi checkout module instead renders the full [woocommerce_checkout]
68 * shortcode, which relies on those standard hooks, so they are never re-added and the
69 * order review section renders empty. We re-attach them here for WPFunnels checkout
70 * steps only, leaving genuine Divi WooCommerce checkouts untouched.
71 *
72 * @return void
73 */
74 public function restore_order_review_hooks() {
75 if ( ! Wpfnl_functions::check_if_this_is_step_type( 'checkout' ) ) {
76 return;
77 }
78
79 if ( ! has_action( 'woocommerce_checkout_order_review', 'woocommerce_order_review' ) ) {
80 add_action( 'woocommerce_checkout_order_review', 'woocommerce_order_review', 10 );
81 }
82
83 if ( ! has_action( 'woocommerce_checkout_order_review', 'woocommerce_checkout_payment' ) ) {
84 add_action( 'woocommerce_checkout_order_review', 'woocommerce_checkout_payment', 20 );
85 }
86 }
87
88 /**
89 * Define WC_GZD_DISABLE_CHECKOUT_ADJUSTMENTS on WPFunnels funnel checkout pages.
90 *
91 * Germanized's wc_gzd_maybe_disable_checkout_adjustments() reads this
92 * constant at woocommerce_before_checkout_form priority -999. When true it:
93 * - removes the hooks that temporarily hide woocommerce_order_button_html,
94 * - removes woocommerce_gzd_template_order_submit from
95 * woocommerce_checkout_order_review (prevents a duplicate button),
96 * - moves legal checkboxes to woocommerce_review_order_before_payment so
97 * they still display inside WPFunnels' payment.php template, and
98 * - outputs a hidden wc_gzd_checkout_disabled field so AJAX order-review
99 * fragments also receive the disabled flag.
100 *
101 * @return void
102 */
103 public function maybe_disable_checkout_adjustments() {
104 if ( ! Wpfnl_functions::check_if_this_is_step_type( 'checkout' ) ) {
105 return;
106 }
107
108 if ( ! defined( 'WC_GZD_DISABLE_CHECKOUT_ADJUSTMENTS' ) ) {
109 define( 'WC_GZD_DISABLE_CHECKOUT_ADJUSTMENTS', true );
110 }
111 }
112
113 /**
114 * Send Germanized order confirmation email for upsell/downsell orders.
115 *
116 * Germanized prevents the standard WooCommerce notification hooks from
117 * firing and relies on woocommerce_payment_successful_result to send its
118 * own confirmation. That filter is never applied during WPFunnels'
119 * AJAX-based offer acceptance, so we trigger it manually here.
120 *
121 * Only acts on child/separate orders (identified by _wpfunnels_offer_parent_id
122 * meta) because the main-order path does not call payment_complete() again
123 * and therefore is unaffected by Germanized's hook removal.
124 *
125 * @param \WC_Order $order Child order created for the upsell/downsell.
126 * @param array $_offer_product Offer product data (unused; required by hook signature).
127 * @return void
128 */
129 public function send_offer_order_confirmation( $order, $_offer_product ) {
130 if ( ! $this->maybe_activate() ) {
131 return;
132 }
133
134 if ( ! is_a( $order, 'WC_Order' ) ) {
135 return;
136 }
137
138 // Only trigger for child (separate) orders – these are the ones whose
139 // payment_complete() call gets intercepted by Germanized.
140 if ( ! $order->get_meta( '_wpfunnels_offer_parent_id' ) ) {
141 return;
142 }
143
144 if ( ! function_exists( 'WC_germanized' ) ) {
145 return;
146 }
147
148 $gzd = \WC_germanized();
149 if ( ! isset( $gzd->emails ) || ! is_object( $gzd->emails ) ) {
150 return;
151 }
152
153 if ( ! function_exists( 'wc_gzd_send_instant_order_confirmation' ) ) {
154 return;
155 }
156
157 if ( \wc_gzd_send_instant_order_confirmation( $order ) ) {
158 $gzd->emails->confirm_order( $order );
159 }
160 }
161
162 /**
163 * Check whether WooCommerce Germanized is active.
164 *
165 * @return bool
166 */
167 public function maybe_activate() {
168 return defined( 'WC_GERMANIZED_VERSION' );
169 }
170 }
171