| 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 |
// Trigger Germanized's order confirmation for upsell/downsell child orders. |
| 50 |
add_action( 'wpfunnels/offer_accepted', array( $this, 'send_offer_order_confirmation' ), 10, 2 ); |
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* Define WC_GZD_DISABLE_CHECKOUT_ADJUSTMENTS on WPFunnels funnel checkout pages. |
| 55 |
* |
| 56 |
* Germanized's wc_gzd_maybe_disable_checkout_adjustments() reads this |
| 57 |
* constant at woocommerce_before_checkout_form priority -999. When true it: |
| 58 |
* - removes the hooks that temporarily hide woocommerce_order_button_html, |
| 59 |
* - removes woocommerce_gzd_template_order_submit from |
| 60 |
* woocommerce_checkout_order_review (prevents a duplicate button), |
| 61 |
* - moves legal checkboxes to woocommerce_review_order_before_payment so |
| 62 |
* they still display inside WPFunnels' payment.php template, and |
| 63 |
* - outputs a hidden wc_gzd_checkout_disabled field so AJAX order-review |
| 64 |
* fragments also receive the disabled flag. |
| 65 |
* |
| 66 |
* @return void |
| 67 |
*/ |
| 68 |
public function maybe_disable_checkout_adjustments() { |
| 69 |
if ( ! Wpfnl_functions::check_if_this_is_step_type( 'checkout' ) ) { |
| 70 |
return; |
| 71 |
} |
| 72 |
|
| 73 |
if ( ! defined( 'WC_GZD_DISABLE_CHECKOUT_ADJUSTMENTS' ) ) { |
| 74 |
define( 'WC_GZD_DISABLE_CHECKOUT_ADJUSTMENTS', true ); |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
/** |
| 79 |
* Send Germanized order confirmation email for upsell/downsell orders. |
| 80 |
* |
| 81 |
* Germanized prevents the standard WooCommerce notification hooks from |
| 82 |
* firing and relies on woocommerce_payment_successful_result to send its |
| 83 |
* own confirmation. That filter is never applied during WPFunnels' |
| 84 |
* AJAX-based offer acceptance, so we trigger it manually here. |
| 85 |
* |
| 86 |
* Only acts on child/separate orders (identified by _wpfunnels_offer_parent_id |
| 87 |
* meta) because the main-order path does not call payment_complete() again |
| 88 |
* and therefore is unaffected by Germanized's hook removal. |
| 89 |
* |
| 90 |
* @param \WC_Order $order Child order created for the upsell/downsell. |
| 91 |
* @param array $_offer_product Offer product data (unused; required by hook signature). |
| 92 |
* @return void |
| 93 |
*/ |
| 94 |
public function send_offer_order_confirmation( $order, $_offer_product ) { |
| 95 |
if ( ! $this->maybe_activate() ) { |
| 96 |
return; |
| 97 |
} |
| 98 |
|
| 99 |
if ( ! is_a( $order, 'WC_Order' ) ) { |
| 100 |
return; |
| 101 |
} |
| 102 |
|
| 103 |
// Only trigger for child (separate) orders – these are the ones whose |
| 104 |
// payment_complete() call gets intercepted by Germanized. |
| 105 |
if ( ! $order->get_meta( '_wpfunnels_offer_parent_id' ) ) { |
| 106 |
return; |
| 107 |
} |
| 108 |
|
| 109 |
if ( ! function_exists( 'WC_germanized' ) ) { |
| 110 |
return; |
| 111 |
} |
| 112 |
|
| 113 |
$gzd = \WC_germanized(); |
| 114 |
if ( ! isset( $gzd->emails ) || ! is_object( $gzd->emails ) ) { |
| 115 |
return; |
| 116 |
} |
| 117 |
|
| 118 |
if ( ! function_exists( 'wc_gzd_send_instant_order_confirmation' ) ) { |
| 119 |
return; |
| 120 |
} |
| 121 |
|
| 122 |
if ( \wc_gzd_send_instant_order_confirmation( $order ) ) { |
| 123 |
$gzd->emails->confirm_order( $order ); |
| 124 |
} |
| 125 |
} |
| 126 |
|
| 127 |
/** |
| 128 |
* Check whether WooCommerce Germanized is active. |
| 129 |
* |
| 130 |
* @return bool |
| 131 |
*/ |
| 132 |
public function maybe_activate() { |
| 133 |
return defined( 'WC_GERMANIZED_VERSION' ); |
| 134 |
} |
| 135 |
} |
| 136 |
|