Created
April 15, 2021 14:30
-
-
Save xlplugins/4432a8dbf0f26823b112c2a770485f50 to your computer and use it in GitHub Desktop.
Restore cart data on cartflows checkout
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if(function_exists('BWFAN_Core')){ | |
add_filter( 'cartflows_global_checkout_url', 'bwfan_passing_abandoned_args', 9.5, 1 ); | |
if(!function_exists('bwfan_passing_abandoned_args')){ | |
function bwfan_passing_abandoned_args( $link ) { | |
if ( ! isset( $_GET['bwfan-ab-id'] ) || empty( $_GET['bwfan-ab-id'] ) ) { | |
return $link; | |
} | |
$link = add_query_arg( array( 'bwfan-ab-id' => sanitize_text_field( $_GET['bwfan-ab-id'] ) ), $link ); | |
if ( isset( $_GET['automation-id'] ) ) { | |
$link = add_query_arg( array( 'automation-id' => sanitize_text_field( $_GET['automation-id'] ) ), $link ); | |
} | |
if ( isset( $_GET['track-id'] ) ) { | |
$link = add_query_arg( array( 'track-id' => sanitize_text_field( $_GET['track-id'] ) ), $link ); | |
} | |
return $link; | |
} | |
} | |
add_filter( 'woocommerce_checkout_get_value', 'bwfan_filled_checkout_details_cartflows', 10, 2 ); | |
if(!function_exists('bwfan_filled_checkout_details_cartflows')){ | |
function bwfan_filled_checkout_details_cartflows( $value, $input ) { | |
global $wpdb; | |
if ( ! isset( $_GET['bwfan-ab-id'] ) || empty( $_GET['bwfan-ab-id'] ) || is_ajax() || is_admin() ) { //phpcs:ignore WordPress.Security.NonceVerification | |
return $value; | |
} | |
$token = sanitize_text_field( $_GET['bwfan-ab-id'] ); //phpcs:ignore WordPress.Security.NonceVerification, WordPress.Security.ValidatedSanitizedInput | |
$query = $wpdb->prepare( "Select * from {table_name} WHERE token LIKE %s", $token ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQLPlaceholders | |
$cart_details = BWFAN_Model_Abandonedcarts::get_results( $query ); | |
if ( empty( $cart_details ) || ! isset( $cart_details[0] ) ) { | |
return $value; | |
} | |
$checkout_data = isset( $cart_details[0]['checkout_data'] ) ? json_decode( $cart_details[0]['checkout_data'], true ) : []; | |
$abandoned_email = isset($cart_details[0]['email'])?$cart_details[0]['email']:null; | |
if ( empty( $checkout_data ) ) { | |
return $value; | |
} | |
if ( 'billing_email' === $input ) { | |
$checkout['fields'][$input] = $abandoned_email; | |
$value = $checkout['fields'][$input]; | |
}else{ | |
$value = $checkout_data['fields'][ $input ]; | |
} | |
return $value; | |
} | |
} | |
add_filter('bwfan_after_cart_restored_redirect','bwfan_no_abandoned_redirect',10,1); | |
if(!function_exists('bwfan_no_abandoned_redirect')){ | |
function bwfan_no_abandoned_redirect($redirect){ | |
return true; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment