| 1 |
<?php |
| 2 |
/** |
| 3 |
* WooCommerce Germanized Compatibility |
| 4 |
* |
| 5 |
* When Germanized is active it removes standard WooCommerce order notification |
| 6 |
* hooks (customer_processing_order, new_order) before the order status changes, |
| 7 |
* then sends its own confirmation via the woocommerce_payment_successful_result |
| 8 |
* filter. That filter never fires for WPFunnels upsell/downsell AJAX requests, |
| 9 |
* so the confirmation email is silently dropped. |
| 10 |
* |
| 11 |
* This class hooks into wpfunnels/offer_accepted – which fires after a child |
| 12 |
* order has been created and payment_complete() called – and explicitly |
| 13 |
* triggers Germanized's own confirm_order() so the customer and admin |
| 14 |
* receive their order confirmation. |
| 15 |
* |
| 16 |
* @package WPFunnels\Compatibility\Plugin |
| 17 |
*/ |
| 18 |
namespace WPFunnels\Compatibility\Plugin; |
| 19 |
|
| 20 |
use WPFunnels\Traits\SingletonTrait; |
| 21 |
|
| 22 |
class WooCommerceGermanized extends PluginCompatibility { |
| 23 |
use SingletonTrait; |
| 24 |
|
| 25 |
/** |
| 26 |
* Register hooks. |
| 27 |
* |
| 28 |
* @return void |
| 29 |
*/ |
| 30 |
public function init() { |
| 31 |
add_action( 'wpfunnels/offer_accepted', array( $this, 'send_offer_order_confirmation' ), 10, 2 ); |
| 32 |
} |
| 33 |
|
| 34 |
/** |
| 35 |
* Send Germanized order confirmation email for upsell/downsell orders. |
| 36 |
* |
| 37 |
* Germanized prevents the standard WooCommerce notification hooks from |
| 38 |
* firing and relies on woocommerce_payment_successful_result to send its |
| 39 |
* own confirmation. That filter is never applied during WPFunnels' |
| 40 |
* AJAX-based offer acceptance, so we trigger it manually here. |
| 41 |
* |
| 42 |
* Only acts on child/separate orders (identified by _wpfunnels_offer_parent_id |
| 43 |
* meta) because the main-order path does not call payment_complete() again |
| 44 |
* and therefore is unaffected by Germanized's hook removal. |
| 45 |
* |
| 46 |
* @param \WC_Order $order The order object (child order when using |
| 47 |
* separate-order mode, main order otherwise). |
| 48 |
* @param array $offer_product Offer product data. |
| 49 |
* @return void |
| 50 |
*/ |
| 51 |
public function send_offer_order_confirmation( $order, $offer_product ) { |
| 52 |
if ( ! $this->maybe_activate() ) { |
| 53 |
return; |
| 54 |
} |
| 55 |
|
| 56 |
if ( ! is_a( $order, 'WC_Order' ) ) { |
| 57 |
return; |
| 58 |
} |
| 59 |
|
| 60 |
// Only trigger for child (separate) orders – these are the ones whose |
| 61 |
// payment_complete() call gets intercepted by Germanized. |
| 62 |
if ( ! $order->get_meta( '_wpfunnels_offer_parent_id' ) ) { |
| 63 |
return; |
| 64 |
} |
| 65 |
|
| 66 |
if ( ! function_exists( 'WC_germanized' ) ) { |
| 67 |
return; |
| 68 |
} |
| 69 |
|
| 70 |
$gzd = WC_germanized(); |
| 71 |
if ( ! isset( $gzd->emails ) || ! is_object( $gzd->emails ) ) { |
| 72 |
return; |
| 73 |
} |
| 74 |
|
| 75 |
if ( ! function_exists( 'wc_gzd_send_instant_order_confirmation' ) ) { |
| 76 |
return; |
| 77 |
} |
| 78 |
|
| 79 |
if ( wc_gzd_send_instant_order_confirmation( $order ) ) { |
| 80 |
$gzd->emails->confirm_order( $order ); |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
/** |
| 85 |
* Check whether WooCommerce Germanized is active. |
| 86 |
* |
| 87 |
* @return bool |
| 88 |
*/ |
| 89 |
public function maybe_activate() { |
| 90 |
return defined( 'WC_GERMANIZED_VERSION' ); |
| 91 |
} |
| 92 |
} |
| 93 |
|