| 1 |
<?php |
| 2 |
/** |
| 3 |
* Mail Mint Compatibility |
| 4 |
* |
| 5 |
* @package WPFunnels\Compatibility\Plugin |
| 6 |
*/ |
| 7 |
namespace WPFunnels\Compatibility\Plugin; |
| 8 |
|
| 9 |
use WPFunnels\Traits\SingletonTrait; |
| 10 |
|
| 11 |
/** |
| 12 |
* Mail Mint Compatibility |
| 13 |
* |
| 14 |
* Keeps a cart restored from a Mail Mint abandoned cart recovery link intact when the |
| 15 |
* link lands on a funnel checkout step. |
| 16 |
* |
| 17 |
* @package WPFunnels\Compatibility\Plugin |
| 18 |
*/ |
| 19 |
class MailMint extends PluginCompatibility { |
| 20 |
use SingletonTrait; |
| 21 |
|
| 22 |
/** |
| 23 |
* Initiate Filters/Hook |
| 24 |
* |
| 25 |
* @since 3.13.3 |
| 26 |
*/ |
| 27 |
public function init() { |
| 28 |
add_filter( 'wpfunnels/allow_initiate_funnel_checkout', array( $this, 'allow_initiate_funnel_checkout' ), 10, 2 ); |
| 29 |
} |
| 30 |
|
| 31 |
/** |
| 32 |
* Skip rebuilding the funnel cart when the visitor arrives from a recovery link. |
| 33 |
* |
| 34 |
* Mail Mint Pro restores the abandoned cart on `wp`, then redirects to the checkout page |
| 35 |
* the cart was captured on with `mint-cart-restored=success`. On a funnel checkout step |
| 36 |
* the checkout would then empty the cart and re-add the step's default products, |
| 37 |
* throwing away the restored quantities, variations and order bumps. |
| 38 |
* |
| 39 |
* The query arg alone is not trusted, since anyone can add it to a URL. Mail Mint keeps |
| 40 |
* the restored cart in the WooCommerce session until an order is placed, and that cart |
| 41 |
* must belong to this step. Otherwise the funnel cart is built as usual. |
| 42 |
* |
| 43 |
* @param bool $allow Whether to initiate the funnel checkout. |
| 44 |
* @param int $funnel_id Funnel ID. |
| 45 |
* |
| 46 |
* @return bool |
| 47 |
* @since 3.13.3 |
| 48 |
*/ |
| 49 |
public function allow_initiate_funnel_checkout( $allow, $funnel_id ) { |
| 50 |
if ( ! $allow || ! isset( $_GET['mint-cart-restored'] ) || 'success' !== $_GET['mint-cart-restored'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 51 |
return $allow; |
| 52 |
} |
| 53 |
|
| 54 |
if ( ! function_exists( 'WC' ) || ! WC()->session || ! WC()->cart || WC()->cart->is_empty() ) { |
| 55 |
return $allow; |
| 56 |
} |
| 57 |
|
| 58 |
$restored = WC()->session->get( 'mint_restored_cart_detail' ); |
| 59 |
if ( empty( $restored['checkout_page_id'] ) || (int) $restored['checkout_page_id'] !== (int) get_the_ID() ) { |
| 60 |
return $allow; |
| 61 |
} |
| 62 |
|
| 63 |
return false; |
| 64 |
} |
| 65 |
|
| 66 |
/** |
| 67 |
* Check if Mail Mint is activated |
| 68 |
* |
| 69 |
* @return bool |
| 70 |
* @since 3.13.3 |
| 71 |
*/ |
| 72 |
public function maybe_activate() { |
| 73 |
return defined( 'MRM_VERSION' ); |
| 74 |
} |
| 75 |
} |
| 76 |
|