Skip to content

Commit

Permalink
fix: expired session errors
Browse files Browse the repository at this point in the history
  • Loading branch information
chickenn00dle committed Jun 18, 2024
1 parent b327bd9 commit 84116ff
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 21 deletions.
9 changes: 5 additions & 4 deletions includes/class-modal-checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public static function init() {
add_filter( 'googlesitekit_adsense_tag_blocked', [ __CLASS__, 'is_modal_checkout' ] );
add_filter( 'googlesitekit_tagmanager_tag_blocked', [ __CLASS__, 'is_modal_checkout' ] );
add_filter( 'jetpack_active_modules', [ __CLASS__, 'jetpack_active_modules' ] );
add_filter( 'woocommerce_checkout_update_order_review_expired', [ __CLASS__, 'is_not_modal_checkout_filter' ] );

/**
* Ensure that options to limit the number of subscriptions per product are respected.
Expand Down Expand Up @@ -178,8 +179,6 @@ public static function process_checkout_request() {
$product_id = $variation_id;
}

\WC()->cart->empty_cart();

$referer = wp_get_referer();
$params = [];
$parsed_url = wp_parse_url( $referer );
Expand Down Expand Up @@ -247,6 +246,7 @@ function ( $item ) {
*/
$cart_item_data = apply_filters( 'newspack_blocks_modal_checkout_cart_item_data', $cart_item_data );

\WC()->cart->empty_cart();
\WC()->cart->add_to_cart( $product_id, 1, 0, [], $cart_item_data );

$query_args = [];
Expand Down Expand Up @@ -593,8 +593,9 @@ public static function enqueue_modal( $product_id = null ) {
'newspack-blocks-modal',
'newspackBlocksModal',
[
'newspack_class_prefix' => self::get_class_prefix(),
'labels' => [
'checkout_registration_flag' => self::CHECKOUT_REGISTRATION_FLAG,
'newspack_class_prefix' => self::get_class_prefix(),
'labels' => [
'auth_modal_title' => self::get_modal_checkout_labels( 'auth_modal_title' ),
'signin_modal_title' => self::get_modal_checkout_labels( 'signin_modal_title' ),
'register_modal_title' => self::get_modal_checkout_labels( 'register_modal_title' ),
Expand Down
1 change: 1 addition & 0 deletions src/modal-checkout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ domReady(
} else {
$nyp.find( 'input[name="price"]' ).focus();
}
$( document.body ).trigger( 'update_checkout' );
},
complete: () => {
input.attr( 'disabled', false );
Expand Down
20 changes: 3 additions & 17 deletions src/modal-checkout/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,6 @@ const IFRAME_CONTAINER_ID = 'newspack_modal_checkout_container';
const MODAL_CHECKOUT_ID = 'newspack_modal_checkout';
const MODAL_CLASS_PREFIX = `${ CLASS_PREFIX }__modal`;

/**
* Create a hidden input element.
*
* @param {string} name The name of the input.
* @param {string} value The value of the input.
*
* @return {HTMLInputElement} The hidden input element.
*/
function createHiddenInput( name, value ) {
const input = document.createElement( 'input' );
input.name = name;
input.value = value;
input.type = 'hidden';
return input;
}

domReady( () => {
const modalCheckout = document.querySelector( `#${ MODAL_CHECKOUT_ID }` );

Expand Down Expand Up @@ -317,7 +301,9 @@ domReady( () => {
title: newspackBlocksModal.labels.auth_modal_title,
callback: () => {
// Signal checkout registration.
form.appendChild( createHiddenInput( '_newspack_checkout_registration', '1' ) );
form.appendChild(
createHiddenInput( newspackBlocksModal.checkout_registration_flag, '1' )
);
// form.submit does not trigger submit event listener, so we use requestSubmit.
form.requestSubmit( form.querySelector( 'button[type="submit"]' ) );
},
Expand Down

0 comments on commit 84116ff

Please sign in to comment.