| 1 |
<?php |
| 2 |
/** |
| 3 |
* CartLift Compatibility |
| 4 |
* |
| 5 |
* @package WPFunnels\Compatibility\Plugin |
| 6 |
*/ |
| 7 |
namespace WPFunnels\Compatibility\Plugin; |
| 8 |
|
| 9 |
use WPFunnels\Wpfnl_functions; |
| 10 |
use WPFunnels\Traits\SingletonTrait; |
| 11 |
|
| 12 |
/** |
| 13 |
* CartLift Compatibility |
| 14 |
* |
| 15 |
* @package WPFunnels\Compatibility\CartLift |
| 16 |
*/ |
| 17 |
class CartLift extends PluginCompatibility{ |
| 18 |
use SingletonTrait; |
| 19 |
|
| 20 |
/** |
| 21 |
* Filters/Hook from Cart Lift |
| 22 |
* to initiate the necessary updates. |
| 23 |
* |
| 24 |
* @since 3.0.0 |
| 25 |
*/ |
| 26 |
public function init() { |
| 27 |
add_filter( 'cl_default_general_settings', [ $this, 'update_cl_general_settings' ] ); |
| 28 |
add_action( 'cl_after_abandoned_cart_tracking_field', [ $this, 'render_funnel_global_option' ] ); |
| 29 |
add_filter( 'cl_cart_tracking_status', [ $this, 'update_cl_cart_tracking_status' ] ); |
| 30 |
add_filter( 'cl_cart_tracking_status_ajax', [ $this, 'update_cl_cart_tracking_status' ] ); |
| 31 |
add_filter( 'cl_cart_details_before_update', [ $this, 'update_cl_cart_details' ], 10, 2 ); |
| 32 |
add_filter( 'cl_cart_details_before_update_ajax', [ $this, 'update_cl_cart_details' ], 10, 2 ); |
| 33 |
add_filter( 'cl_email_checkout_url', [ $this, 'get_cl_funnel_checkout_url' ], 10, 3 ); |
| 34 |
} |
| 35 |
|
| 36 |
/** |
| 37 |
* Add WPFunnels tracking option |
| 38 |
* in Cart Lift global general settings |
| 39 |
* |
| 40 |
* @param $default_settings |
| 41 |
* |
| 42 |
* @return mixed |
| 43 |
* @since 3.0.0 |
| 44 |
*/ |
| 45 |
public function update_cl_general_settings( $default_settings ) { |
| 46 |
$default_settings[ 'wpfunnels_tracking' ] = 0; |
| 47 |
return $default_settings; |
| 48 |
} |
| 49 |
|
| 50 |
/** |
| 51 |
* Render markups for WPFunnels |
| 52 |
* global general settings option. |
| 53 |
* |
| 54 |
* @param $general_data |
| 55 |
* |
| 56 |
* @since 3.0.0 |
| 57 |
*/ |
| 58 |
public function render_funnel_global_option( $general_data ) { |
| 59 |
$wpfunnels_tracking_status = 'no'; |
| 60 |
$wpfunnels_tracking = isset( $general_data['wpfunnels_tracking'] ) ? $general_data['wpfunnels_tracking'] : 0; |
| 61 |
if($wpfunnels_tracking) { |
| 62 |
$wpfunnels_tracking_status = 'yes'; |
| 63 |
} |
| 64 |
?> |
| 65 |
<div class="cl-form-group"> |
| 66 |
<div class="cl-global-tooltip-area"> |
| 67 |
<span class="title"><?php echo __( 'Enable abandoned cart tracking for WPFunnels:', 'wpfnl' ); ?></span> |
| 68 |
|
| 69 |
<div class="tooltip"> |
| 70 |
<span class="icon"> |
| 71 |
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" fill="none"> |
| 72 |
<rect x="1" y="1.1925" width="14" height="14" rx="7" stroke="#535963"/> |
| 73 |
<path d="M6 5.69543C6.0741 4.80132 6.85381 4.13315 7.74894 4.19668H8.24864C9.14377 4.13315 9.92347 4.80132 9.99758 5.69543C10.0354 6.36175 9.62793 6.97278 8.99818 7.19418C8.30536 7.60992 7.91577 8.38893 7.99879 9.1925" stroke="#535963" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/> |
| 74 |
<path d="M8.5 12.19V12.195" stroke="#535963" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/> |
| 75 |
</svg> |
| 76 |
</span> |
| 77 |
<p><?php echo __( 'This will enable tracking abandoned cart from WPFunnels', 'wpfnl' ); ?></p> |
| 78 |
</div> |
| 79 |
|
| 80 |
</div> |
| 81 |
|
| 82 |
<span class="cl-switcher"> |
| 83 |
<input class="cl-toggle-option" type="checkbox" id="wpfunnels_tracking" name="wpfunnels_tracking" data-status="<?php echo $wpfunnels_tracking_status; ?>" value="<?php echo $wpfunnels_tracking; ?>" <?php checked( '1', $wpfunnels_tracking ); ?>/> |
| 84 |
<label for="wpfunnels_tracking"></label> |
| 85 |
</span> |
| 86 |
</div> |
| 87 |
<?php |
| 88 |
} |
| 89 |
|
| 90 |
/** |
| 91 |
* Update cart tracking status for WPFunnels |
| 92 |
* while saving cart data into Cart Lift DB. |
| 93 |
* |
| 94 |
* @param $cart_track |
| 95 |
* |
| 96 |
* @return mixed|string |
| 97 |
* @since 3.0.0 |
| 98 |
*/ |
| 99 |
public function update_cl_cart_tracking_status( $cart_track ) { |
| 100 |
$post_id = get_the_ID(); |
| 101 |
$post_type = get_post_type( $post_id ); |
| 102 |
|
| 103 |
if( $post_id > 1 && $post_type === 'wpfunnel_steps') { |
| 104 |
return cl_get_general_settings_data( 'wpfunnels_tracking' ); |
| 105 |
} |
| 106 |
elseif( !empty( $_POST ) && isset( $_POST['post_data'] ) ) { |
| 107 |
$post_data = array(); |
| 108 |
if( !empty( $post_data ) && isset( $post_data['_wpfunnels_funnel_id'] ) ) { |
| 109 |
$funnel_id = $post_data['_wpfunnels_funnel_id']; |
| 110 |
$funnel_data = Wpfnl_functions::get_funnel_data( $funnel_id ); |
| 111 |
if( $funnel_data !== '' ) { |
| 112 |
return cl_get_general_settings_data( 'wpfunnels_tracking' ); |
| 113 |
} |
| 114 |
} |
| 115 |
} |
| 116 |
elseif( !empty( $_POST ) && isset( $_POST['wpfunnels_checkout_id'] ) ) { |
| 117 |
$wpfunnels_checkout_id = $_POST['wpfunnels_checkout_id']; |
| 118 |
$funnel_id = Wpfnl_functions::get_funnel_id_from_step( $wpfunnels_checkout_id ); |
| 119 |
|
| 120 |
if( $funnel_id != 0 ) { |
| 121 |
return cl_get_general_settings_data( 'wpfunnels_tracking' ); |
| 122 |
} |
| 123 |
} |
| 124 |
return $cart_track; |
| 125 |
} |
| 126 |
|
| 127 |
/** |
| 128 |
* Add funnel id and step id from WPFunnels |
| 129 |
* while saving cart data [in cart_meta] if the checkout |
| 130 |
* is from any funnel checkout from WPFunnels. |
| 131 |
* |
| 132 |
* @param $cart_details |
| 133 |
* @param $session_id |
| 134 |
* |
| 135 |
* @return mixed |
| 136 |
* @since 3.0.0 |
| 137 |
*/ |
| 138 |
public function update_cl_cart_details( $cart_details, $session_id ) { |
| 139 |
$post_id = get_the_ID(); |
| 140 |
if( $post_id != 0 ) { |
| 141 |
$post_type = get_post_type( get_the_ID() ); |
| 142 |
|
| 143 |
if( $post_type && $post_type === 'wpfunnel_steps' ) { |
| 144 |
$step_id = $post_id; |
| 145 |
$funnel_id = Wpfnl_functions::get_funnel_id_from_step($step_id); |
| 146 |
$cart_meta = array(); |
| 147 |
if( isset( $cart_details['cart_meta'] ) ) { |
| 148 |
$cart_meta = unserialize( $cart_details['cart_meta'] ); |
| 149 |
} |
| 150 |
$cart_meta['wpfunnel_id'] = $funnel_id; |
| 151 |
$cart_meta['wpfunnel_step_id'] = $step_id; |
| 152 |
$cart_details['cart_meta'] = serialize($cart_meta); |
| 153 |
} |
| 154 |
} |
| 155 |
return $cart_details; |
| 156 |
} |
| 157 |
|
| 158 |
/** |
| 159 |
* Modify checkout url of checkout button in |
| 160 |
* the campaign email for cart abandoned |
| 161 |
* from any funnel checkout build from WPFunnels. |
| 162 |
* |
| 163 |
* @param $checkout_url |
| 164 |
* @param $token |
| 165 |
* @param $email_data |
| 166 |
* |
| 167 |
* @return mixed|string |
| 168 |
* @since 3.0.0 |
| 169 |
*/ |
| 170 |
public function get_cl_funnel_checkout_url( $checkout_url, $token, $email_data ) { |
| 171 |
if( !empty( $email_data ) && isset( $email_data->cart_meta ) ){ |
| 172 |
$cart_meta = unserialize( $email_data->cart_meta ); |
| 173 |
$funnel_id = isset( $cart_meta['wpfunnel_id'] ) ? $cart_meta['wpfunnel_id'] : 0; |
| 174 |
$step_id = isset( $cart_meta['wpfunnels_checkout_id'] ) ? $cart_meta['wpfunnels_checkout_id'] : 0; |
| 175 |
|
| 176 |
if( $funnel_id != 0 ) { |
| 177 |
if( Wpfnl_functions::is_global_funnel( $funnel_id ) ) { |
| 178 |
return get_permalink( $step_id ) . '?cl_token=' . $token; |
| 179 |
} |
| 180 |
return get_permalink( $step_id ) . '?cl_token=' . 'wpfunnels_checkout'; |
| 181 |
} |
| 182 |
} |
| 183 |
return $checkout_url; |
| 184 |
} |
| 185 |
|
| 186 |
|
| 187 |
/** |
| 188 |
* Check if cart list is activated |
| 189 |
* |
| 190 |
* @return bool |
| 191 |
* @since 2.7.7 |
| 192 |
*/ |
| 193 |
public function maybe_activate() |
| 194 |
{ |
| 195 |
if (in_array('cart-lift/cart-lift.php', apply_filters('active_plugins', get_option('active_plugins')))) { |
| 196 |
return true; |
| 197 |
}elseif( function_exists('is_plugin_active') ){ |
| 198 |
if( is_plugin_active( 'cart-lift/cart-lift.php' )){ |
| 199 |
return true; |
| 200 |
} |
| 201 |
} |
| 202 |
return false; |
| 203 |
} |
| 204 |
} |
| 205 |
|