Ecommerce Shopify WordPress Discussion

Check programatically if Cart or Checkout Blocks are used in WooCommerce

How to identify in the backend if the store is using Checkout blocks [classic_checkout] or WooCommerce checkout with shortcode [woocommerce_checkout]. I'm testing a payment gateway and I use enqueue_script to add the JS to the frontend. What is the best way to validate whether a store is using the Blocks-compatible [classic_checkout] block or not, so that scripts can only be queued when necessary?
I finally found the way via has_block_in_page( $page, $block_name ) function located in WC_Blocks_Utils Class. You can use it for Checkout as follows: // Conditional function that check if Checkout page use Checkout Blocks function is_checkout_block() { return WC_Blocks_Utils::has_block_in_page( wc_get_page_id('checkout'), 'woocommerce/checkout' ); } For cart page, you can use: // Conditional function that check if Cart page use Cart Blocks function is_checkout_block() { return WC_Blocks_Utils::has_block_in_page( wc_get_page_id('cart'), 'woocommerce/cart' ); } Tested and works

February 13, 2024

TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.