Skip to content

Commit

Permalink
address changes
Browse files Browse the repository at this point in the history
  • Loading branch information
senadir committed Feb 9, 2024
1 parent 8283994 commit 5a8ca44
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,16 @@ public function capture_order_confirmation_view() {

$order = wc_get_order( $order_id );

$order_source = $order->get_created_via();
$order_source = $order->get_created_via();
$checkout_page_contains_checkout_block = '0';
$checkout_page_contains_checkout_shortcode = '0';

if ( 'store-api' === $order_source ) {
$checkout_page_contains_checkout_block = '1';
$checkout_page_contains_checkout_shortcode = '0';
} elseif ( 'checkout' === $order_source ) {
$checkout_page_contains_checkout_block = '0';
$checkout_page_contains_checkout_shortcode = '1';
} else {
$checkout_page_contains_checkout_block = '0';
$checkout_page_contains_checkout_shortcode = '0';
}

$coupons = $order->get_coupons();
Expand Down Expand Up @@ -147,18 +147,27 @@ public function capture_checkout_view() {
$is_checkout = $checkout_page_id && is_page( $checkout_page_id )
|| wc_post_content_has_shortcode( 'woocommerce_checkout' )
|| has_block( 'woocommerce/checkout', $post )
|| has_block( 'woocommerce/classic-shortcode', $post )
|| apply_filters( 'woocommerce_is_checkout', false )
|| \Automattic\Jetpack\Constants::is_defined( 'WOOCOMMERCE_CHECKOUT' );

if ( ! $is_checkout ) {
return;
}

$is_in_checkout_page = $checkout_page_id === $post->ID ? 'Yes' : 'No';
$session = WC()->session;
$is_in_checkout_page = $checkout_page_id === $post->ID ? 'Yes' : 'No';
$checkout_page_contains_checkout_block = '0';
$checkout_page_contains_checkout_shortcode = '1';

$session = WC()->session;
if ( is_object( $session ) ) {
$session->set( 'checkout_page_used', true );
$session->save_data();
$draft_order_id = $session->get( 'store_api_draft_order', 0 );
if ( $draft_order_id ) {
$checkout_page_contains_checkout_block = '1';
$checkout_page_contains_checkout_shortcode = '0';
}
}

// Order received page is also a checkout page, so we need to bail out if we are on that page.
Expand All @@ -172,6 +181,8 @@ public function capture_checkout_view() {
$this->get_cart_checkout_shared_data(),
array(
'from_checkout' => $is_in_checkout_page,
'checkout_page_contains_checkout_block' => $checkout_page_contains_checkout_block,
'checkout_page_contains_checkout_shortcode' => $checkout_page_contains_checkout_shortcode,
)
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,7 @@ function ( $payment_gateway ) {
// Check if jQuery is available
if ( typeof jQuery !== 'undefined' ) {
// This is only triggered on the checkout shortcode.
console.log('running here');
jQuery( document.body ).on( 'init_checkout', function () {
console.log('but not here');
if ( true === cartItem_{$cart_item_key}_logged ) {
return;
}
Expand Down Expand Up @@ -274,15 +272,18 @@ function ( $payment_gateway ) {
const checkoutDataStore = wp.data.select( 'wc/store/checkout' );
// Ensures we're not in Cart, but in Checkout page.
if ( checkoutDataStore.getOrderId() !== 0 ) {
if (
typeof checkoutDataStore !== 'undefined' &&
checkoutDataStore.getOrderId() !== 0
) {
properties.express_checkout = Object.keys( wc.wcBlocksRegistry.getExpressPaymentMethods() );
properties.checkout_page_contains_checkout_block = '1';
properties.checkout_page_contains_checkout_shortcode = '0';
_wca.push( properties );
cartItem_{$cart_item_key}_logged = true;
}
}, 'wc/store/checkout' );
} );
}
"
);
Expand Down Expand Up @@ -330,16 +331,16 @@ public function order_process( $order_id ) {
}
}

$checkout_page_contains_checkout_block = '0';
$checkout_page_contains_checkout_shortcode = '0';

$order_source = $order->get_created_via();
if ( 'store-api' === $order_source ) {
$checkout_page_contains_checkout_block = '1';
$checkout_page_contains_checkout_shortcode = '0';
} elseif ( 'checkout' === $order_source ) {
$checkout_page_contains_checkout_block = '0';
$checkout_page_contains_checkout_shortcode = '1';
} else {
$checkout_page_contains_checkout_block = '0';
$checkout_page_contains_checkout_shortcode = '0';
}

// loop through products in the order and queue a purchase event.
Expand Down

0 comments on commit 5a8ca44

Please sign in to comment.