Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use reliable way to detect checkout page #40523

Open
wants to merge 8 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: added

Use reliable way to detect checkout page

Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ public function capture_cart_view() {
*/
public function capture_checkout_view() {
global $post;

if ( ! $post ) {
bor0 marked this conversation as resolved.
Show resolved Hide resolved
return;
}

$checkout_page_id = wc_get_page_id( 'checkout' );

$is_checkout = $checkout_page_id && is_page( $checkout_page_id )
Expand All @@ -154,7 +159,6 @@ public function capture_checkout_view() {
return;
}

$is_in_checkout_page = $checkout_page_id === $post->ID ? 'Yes' : 'No';
bor0 marked this conversation as resolved.
Show resolved Hide resolved
$checkout_page_contains_checkout_block = '0';
$checkout_page_contains_checkout_shortcode = '1';

Expand All @@ -179,7 +183,7 @@ public function capture_checkout_view() {
array_merge(
$this->get_cart_checkout_shared_data(),
array(
'from_checkout' => $is_in_checkout_page,
'from_checkout' => 'Yes',
'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 @@ -181,7 +181,6 @@ 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() {
global $post;
$checkout_page_id = wc_get_page_id( 'checkout' );
$cart = WC()->cart->get_cart();

Expand All @@ -198,7 +197,7 @@ function ( $payment_gateway ) {

$enabled_payment_options = array_keys( $enabled_payment_options );

$is_in_checkout_page = $checkout_page_id === $post->ID ? 'Yes' : 'No';
$is_in_checkout_page = $checkout_page_id && is_page( $checkout_page_id ) ? 'Yes' : 'No';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WooCommerce core uses the same approach

$session = WC()->session;
if ( is_object( $session ) ) {
$session->set( 'checkout_page_used', true );
Expand Down
Loading