Skip to content

Instantly share code, notes, and snippets.

@esedic
Created June 17, 2025 12:32
Show Gist options
  • Save esedic/51d5c8c49c8398efa3020a683950a94b to your computer and use it in GitHub Desktop.
Save esedic/51d5c8c49c8398efa3020a683950a94b to your computer and use it in GitHub Desktop.
Detecting WooCommerce Block Pages
<?php
function is_wc_cart_block_based() {
$cart_page_id = wc_get_page_id( 'cart' );
if ( $cart_page_id && $cart_page = get_post( $cart_page_id ) ) {
// Check for WooCommerce Cart block
return has_block( 'woocommerce/cart', $cart_page );
}
return false;
}
function is_wc_checkout_block_based() {
$checkout_page_id = wc_get_page_id( 'checkout' );
if ( $checkout_page_id && $checkout_page = get_post( $checkout_page_id ) ) {
// Check for WooCommerce Checkout block
return has_block( 'woocommerce/checkout', $checkout_page );
}
return false;
}
// Usage
if ( is_wc_cart_block_based() ) {
echo 'Cart page is block-based.';
} else {
echo 'Cart page is shortcode-based.';
}
if ( is_wc_checkout_block_based() ) {
echo 'Checkout page is block-based.';
} else {
echo 'Checkout page is shortcode-based.';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment