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-mail-mint.php

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

76 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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