Skip to content

Commit

Permalink
add extra to see from checkout is coming
Browse files Browse the repository at this point in the history
  • Loading branch information
senadir committed Feb 1, 2024
1 parent ef968c1 commit 94f34bd
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,11 @@ public function capture_order_confirmation_view() {
}

if ( is_object( WC()->session ) ) {
$create_account = true === WC()->session->get( 'wc_checkout_createaccount_used' ) ? 'Yes' : 'No';
$create_account = true === WC()->session->get( 'wc_checkout_createaccount_used' ) ? 'Yes' : 'No';
$checkout_page_used = true === WC()->session->get( 'checkout_page_used' ) ? 'Yes' : 'No';
} else {
$create_account = 'No';
$create_account = 'No';
$checkout_page_used = 'No';
}

$this->record_event(
Expand All @@ -111,6 +113,7 @@ public function capture_order_confirmation_view() {
'products' => $this->format_items_to_json( $order->get_items() ),
'order_note' => $order->get_customer_note(),
'shipping_option' => $order->get_shipping_method(),
'from_checkout' => $checkout_page_used,
'checkout_page_contains_checkout_block' => $checkout_page_contains_checkout_block,
'checkout_page_contains_checkout_shortcode' => $checkout_page_contains_checkout_shortcode,
)
Expand Down Expand Up @@ -138,10 +141,26 @@ public function capture_cart_view() {
* Track the checkout page view
*/
public function capture_checkout_view() {
if ( ! is_checkout() ) {
global $post;
$checkout_page_id = wc_get_page_id( 'checkout' );

$is_checkout = $checkout_page_id && is_page( $checkout_page_id )
|| wc_post_content_has_shortcode( 'woocommerce_checkout' )
|| has_block( 'woocommerce/checkout', $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;
if ( is_object( $session ) ) {
$session->set( 'checkout_page_used', true );
$session->save_data();
}

// Order received page is also a checkout page, so we need to bail out if we are on that page.
if ( is_order_received_page() ) {
return;
Expand All @@ -151,7 +170,9 @@ public function capture_checkout_view() {
'woocommerceanalytics_checkout_view',
array_merge(
$this->get_cart_checkout_shared_data(),
array()
array(
'from_checkout' => $is_in_checkout_page,
)
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,9 @@ public function get_shipping_option_for_item( $cart_item_key ) {
* On the Checkout page, trigger an event for each product in the cart
*/
public function checkout_process() {
$cart = WC()->cart->get_cart();
global $post;
$checkout_page_id = wc_get_page_id( 'checkout' );
$cart = WC()->cart->get_cart();

$enabled_payment_options = array_filter(
WC()->payment_gateways->get_available_payment_gateways(),
Expand All @@ -198,6 +200,13 @@ function ( $payment_gateway ) {

$enabled_payment_options = array_keys( $enabled_payment_options );

$is_in_checkout_page = $checkout_page_id === $post->ID ? 'Yes' : 'No';
$session = WC()->session;
if ( is_object( $session ) ) {
$session->set( 'checkout_page_used', true );
$session->save_data();
}

foreach ( $cart as $cart_item_key => $cart_item ) {
/**
* This filter is already documented in woocommerce/templates/cart/cart.php
Expand All @@ -210,6 +219,8 @@ function ( $payment_gateway ) {

$data = $this->get_cart_checkout_shared_data();

$data['from_checkout'] = $is_in_checkout_page;

if ( ! empty( $data['products'] ) ) {
unset( $data['products'] );
}
Expand Down Expand Up @@ -262,15 +273,16 @@ function ( $payment_gateway ) {
}
const checkoutDataStore = wp.data.select( 'wc/store/checkout' );
if ( undefined !== checkoutDataStore && checkoutDataStore.getOrderId() !== 0 ) {
// Ensures we're not in Cart, but in Checkout page.
if ( 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 All @@ -296,9 +308,12 @@ public function order_process( $order_id ) {
$payment_option = $order->get_payment_method();

if ( is_object( WC()->session ) ) {
$create_account = true === WC()->session->get( 'wc_checkout_createaccount_used' ) ? 'Yes' : 'No';
$create_account = true === WC()->session->get( 'wc_checkout_createaccount_used' ) ? 'Yes' : 'No';
$checkout_page_used = true === WC()->session->get( 'checkout_page_used' ) ? 'Yes' : 'No';

} else {
$create_account = 'No';
$create_account = 'No';
$checkout_page_used = 'No';
}

$guest_checkout = $order->get_user() ? 'No' : 'Yes';
Expand Down Expand Up @@ -326,6 +341,7 @@ public function order_process( $order_id ) {
$checkout_page_contains_checkout_block = '0';
$checkout_page_contains_checkout_shortcode = '0';
}

// loop through products in the order and queue a purchase event.
foreach ( $order->get_items() as $order_item ) {
$product_id = is_callable( array( $order_item, 'get_product_id' ) ) ? $order_item->get_product_id() : -1;
Expand All @@ -352,6 +368,7 @@ public function order_process( $order_id ) {
'products_count' => $order_items_count,
'coupon_used' => $order_coupons_count,
'order_value' => $order->get_total(),
'from_checkout' => $checkout_page_used,
'checkout_page_contains_checkout_block' => $checkout_page_contains_checkout_block,
'checkout_page_contains_checkout_shortcode' => $checkout_page_contains_checkout_shortcode,
),
Expand Down

0 comments on commit 94f34bd

Please sign in to comment.