Reloads checkout after registration which fixes #3612, removes some notices preventing login cookie being set, moves cart check for #3162
No perfect solution for #3162. DB locking would probably cause more issues that its worth, we cannot reliably use transactions as some clients still use MyIsam. Best to accept orders and deal with stock conflicts after the fact.
This commit is contained in:
parent
5e51ef1fce
commit
e1631bd084
|
@ -250,55 +250,59 @@ jQuery(document).ready(function($) {
|
|||
url: wc_checkout_params.checkout_url,
|
||||
data: $form.serialize(),
|
||||
success: function( code ) {
|
||||
var result = '';
|
||||
var result = '';
|
||||
|
||||
try {
|
||||
// Get the valid JSON only from the returned string
|
||||
if ( code.indexOf("<!--WC_START-->") >= 0 )
|
||||
code = code.split("<!--WC_START-->")[1]; // Strip off before after WC_START
|
||||
try {
|
||||
// Get the valid JSON only from the returned string
|
||||
if ( code.indexOf("<!--WC_START-->") >= 0 )
|
||||
code = code.split("<!--WC_START-->")[1]; // Strip off before after WC_START
|
||||
|
||||
if ( code.indexOf("<!--WC_END-->") >= 0 )
|
||||
code = code.split("<!--WC_END-->")[0]; // Strip off anything after WC_END
|
||||
if ( code.indexOf("<!--WC_END-->") >= 0 )
|
||||
code = code.split("<!--WC_END-->")[0]; // Strip off anything after WC_END
|
||||
|
||||
// Parse
|
||||
result = $.parseJSON( code );
|
||||
// Parse
|
||||
result = $.parseJSON( code );
|
||||
|
||||
if ( result.result == 'success' ) {
|
||||
|
||||
window.location = decodeURI(result.redirect);
|
||||
|
||||
} else if ( result.result == 'failure' ) {
|
||||
throw "Result failure";
|
||||
} else {
|
||||
throw "Invalid response";
|
||||
}
|
||||
if ( result.result == 'success' ) {
|
||||
window.location = decodeURI(result.redirect);
|
||||
} else if ( result.result == 'failure' ) {
|
||||
throw "Result failure";
|
||||
} else {
|
||||
throw "Invalid response";
|
||||
}
|
||||
catch( err ) {
|
||||
// Remove old errors
|
||||
$('.woocommerce-error, .woocommerce-message').remove();
|
||||
}
|
||||
catch( err ) {
|
||||
|
||||
// Add new errors
|
||||
if ( result.messages )
|
||||
$form.prepend( result.messages );
|
||||
else
|
||||
$form.prepend( code );
|
||||
|
||||
// Cancel processing
|
||||
$form.removeClass('processing').unblock();
|
||||
|
||||
// Lose focus for all fields
|
||||
$form.find( '.input-text, select' ).blur();
|
||||
|
||||
// Scroll to top
|
||||
$('html, body').animate({
|
||||
scrollTop: ($('form.checkout').offset().top - 100)
|
||||
}, 1000);
|
||||
|
||||
// Trigger update in case we need a fresh nonce
|
||||
if ( result.refresh == 'true' )
|
||||
$('body').trigger('update_checkout');
|
||||
if ( result.reload == 'true' ) {
|
||||
window.location.reload();
|
||||
return;
|
||||
}
|
||||
},
|
||||
|
||||
// Remove old errors
|
||||
$('.woocommerce-error, .woocommerce-message').remove();
|
||||
|
||||
// Add new errors
|
||||
if ( result.messages )
|
||||
$form.prepend( result.messages );
|
||||
else
|
||||
$form.prepend( code );
|
||||
|
||||
// Cancel processing
|
||||
$form.removeClass('processing').unblock();
|
||||
|
||||
// Lose focus for all fields
|
||||
$form.find( '.input-text, select' ).blur();
|
||||
|
||||
// Scroll to top
|
||||
$('html, body').animate({
|
||||
scrollTop: ($('form.checkout').offset().top - 100)
|
||||
}, 1000);
|
||||
|
||||
// Trigger update in case we need a fresh nonce
|
||||
if ( result.refresh == 'true' )
|
||||
$('body').trigger('update_checkout');
|
||||
}
|
||||
},
|
||||
dataType: "html"
|
||||
});
|
||||
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -42,7 +42,6 @@ class WC_Checkout {
|
|||
public function __construct () {
|
||||
global $woocommerce;
|
||||
|
||||
add_action( 'woocommerce_checkout_process', array( $this,'checkout_process' ) );
|
||||
add_action( 'woocommerce_checkout_billing', array( $this,'checkout_form_billing' ) );
|
||||
add_action( 'woocommerce_checkout_shipping', array( $this,'checkout_form_shipping' ) );
|
||||
|
||||
|
@ -89,11 +88,8 @@ class WC_Checkout {
|
|||
|
||||
/**
|
||||
* Checkout process
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function checkout_process() {
|
||||
public function check_cart_items() {
|
||||
// When we process the checkout, lets ensure cart items are rechecked to prevent checkout
|
||||
do_action('woocommerce_check_cart_items');
|
||||
}
|
||||
|
@ -378,7 +374,7 @@ class WC_Checkout {
|
|||
$this->posted['terms'] = isset( $_POST['terms'] ) ? 1 : 0;
|
||||
$this->posted['createaccount'] = isset( $_POST['createaccount'] ) ? 1 : 0;
|
||||
$this->posted['payment_method'] = isset( $_POST['payment_method'] ) ? stripslashes( $_POST['payment_method'] ) : '';
|
||||
$this->posted['shipping_method'] = isset( $_POST['shipping_method'] ) ? stripslashes( $_POST['shipping_method'] ) : '';
|
||||
$this->posted['shipping_method'] = isset( $_POST['shipping_method'] ) ? $_POST['shipping_method'] : '';
|
||||
$this->posted['ship_to_different_address'] = isset( $_POST['ship_to_different_address'] ) ? true : false;
|
||||
|
||||
if ( isset( $_POST['shiptobilling'] ) ) {
|
||||
|
@ -593,8 +589,8 @@ class WC_Checkout {
|
|||
|
||||
woocommerce_set_customer_auth_cookie( $this->customer_id );
|
||||
|
||||
// As we are now logged in, checkout will need to refresh to serve a new nonce
|
||||
WC()->session->set( 'refresh_totals', true );
|
||||
// As we are now logged in, checkout will need to refresh to show logged in data
|
||||
WC()->session->set( 'reload_checkout', true );
|
||||
|
||||
// Add customer info from other billing fields
|
||||
if ( $this->posted['billing_first_name'] )
|
||||
|
@ -604,14 +600,15 @@ class WC_Checkout {
|
|||
wp_update_user( array ( 'ID' => $this->customer_id, 'last_name' => $this->posted['billing_last_name'] ) ) ;
|
||||
}
|
||||
|
||||
// Do a final stock check at this point
|
||||
$this->check_cart_items();
|
||||
|
||||
// Abort if errors are present
|
||||
if ( wc_error_count() > 0 )
|
||||
throw new Exception();
|
||||
|
||||
// Create the order
|
||||
$order_id = $this->create_order();
|
||||
|
||||
// Order is saved
|
||||
do_action( 'woocommerce_checkout_order_processed', $order_id, $this->posted );
|
||||
|
||||
// Process payment
|
||||
|
@ -690,11 +687,12 @@ class WC_Checkout {
|
|||
array(
|
||||
'result' => 'failure',
|
||||
'messages' => $messages,
|
||||
'refresh' => isset( $woocommerce->session->refresh_totals ) ? 'true' : 'false'
|
||||
'refresh' => isset( $woocommerce->session->refresh_totals ) ? 'true' : 'false',
|
||||
'reload' => isset( $woocommerce->session->reload_checkout ) ? 'true' : 'false'
|
||||
)
|
||||
) . '<!--WC_END-->';
|
||||
|
||||
unset( $woocommerce->session->refresh_totals );
|
||||
unset( $woocommerce->session->refresh_totals, $woocommerce->session->reload_checkout );
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -348,7 +348,7 @@ class WC_Customer {
|
|||
$tax_based_on = get_option( 'woocommerce_tax_based_on' );
|
||||
|
||||
// Check shipping method at this point to see if we need special handling
|
||||
if ( apply_filters( 'woocommerce_apply_base_tax_for_local_pickup', true ) == true && sizeof( array_intersect( WC()->session->get( 'chosen_shipping_methods' ), apply_filters( 'woocommerce_local_pickup_methods', array( 'local_pickup' ) ) ) ) > 0 ) {
|
||||
if ( apply_filters( 'woocommerce_apply_base_tax_for_local_pickup', true ) == true && sizeof( array_intersect( WC()->session->get( 'chosen_shipping_methods', array() ), apply_filters( 'woocommerce_local_pickup_methods', array( 'local_pickup' ) ) ) ) > 0 ) {
|
||||
$tax_based_on = 'base';
|
||||
}
|
||||
|
||||
|
|
|
@ -78,34 +78,34 @@ class WC_Validation {
|
|||
$alpha5 = "[abdefghjlnpqrstuwxyz]"; // Character 5
|
||||
|
||||
// Expression for postcodes: AN NAA, ANN NAA, AAN NAA, and AANN NAA
|
||||
$pcexp[0] = '^('.$alpha1.'{1}'.$alpha2.'{0,1}[0-9]{1,2})([0-9]{1}'.$alpha5.'{2})$';
|
||||
$pcexp[0] = '/^('.$alpha1.'{1}'.$alpha2.'{0,1}[0-9]{1,2})([0-9]{1}'.$alpha5.'{2})$/';
|
||||
|
||||
// Expression for postcodes: ANA NAA
|
||||
$pcexp[1] = '^('.$alpha1.'{1}[0-9]{1}'.$alpha3.'{1})([0-9]{1}'.$alpha5.'{2})$';
|
||||
$pcexp[1] = '/^('.$alpha1.'{1}[0-9]{1}'.$alpha3.'{1})([0-9]{1}'.$alpha5.'{2})$/';
|
||||
|
||||
// Expression for postcodes: AANA NAA
|
||||
$pcexp[2] = '^('.$alpha1.'{1}'.$alpha2.'[0-9]{1}'.$alpha4.')([0-9]{1}'.$alpha5.'{2})$';
|
||||
$pcexp[2] = '/^('.$alpha1.'{1}'.$alpha2.'[0-9]{1}'.$alpha4.')([0-9]{1}'.$alpha5.'{2})$/';
|
||||
|
||||
// Exception for the special postcode GIR 0AA
|
||||
$pcexp[3] = '^(gir)(0aa)$';
|
||||
$pcexp[3] = '/^(gir)(0aa)$/';
|
||||
|
||||
// Standard BFPO numbers
|
||||
$pcexp[4] = '^(bfpo)([0-9]{1,4})$';
|
||||
$pcexp[4] = '/^(bfpo)([0-9]{1,4})$/';
|
||||
|
||||
// c/o BFPO numbers
|
||||
$pcexp[5] = '^(bfpo)(c\/o[0-9]{1,3})$';
|
||||
$pcexp[5] = '/^(bfpo)(c\/o[0-9]{1,3})$/';
|
||||
|
||||
// Load up the string to check, converting into lowercase and removing spaces
|
||||
$postcode = strtolower($toCheck);
|
||||
$postcode = strtolower( $toCheck );
|
||||
$postcode = str_replace (' ', '', $postcode);
|
||||
|
||||
// Assume we are not going to find a valid postcode
|
||||
$valid = false;
|
||||
|
||||
// Check the string against the six types of postcodes
|
||||
foreach ($pcexp as $regexp) {
|
||||
foreach ( $pcexp as $regexp ) {
|
||||
|
||||
if (ereg($regexp,$postcode, $matches)) {
|
||||
if ( preg_match( $regexp, $postcode, $matches ) ) {
|
||||
|
||||
// Load new postcode back into the form element
|
||||
$toCheck = strtoupper ($matches[1] . ' ' . $matches [2]);
|
||||
|
|
|
@ -122,7 +122,7 @@ function woocommerce_set_customer_auth_cookie( $customer_id ) {
|
|||
|
||||
$current_user = get_user_by( 'id', $customer_id );
|
||||
|
||||
wp_set_auth_cookie( $customer_id, true, is_ssl() );
|
||||
wp_set_auth_cookie( $customer_id, true );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue