Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Ensure WooCommerce Core scripts are dequeued correctly #10624

Merged
merged 3 commits into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
19 changes: 14 additions & 5 deletions src/BlockTypes/Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@ protected function initialize() {
add_action( 'wp_loaded', array( $this, 'register_patterns' ) );
}

/**
* Dequeues the scripts added by WC Core to the Cart page.
*
* @return void
*/
public function dequeue_woocommerce_core_scripts() {
wp_dequeue_script( 'wc-cart' );
wp_dequeue_script( 'wc-password-strength-meter' );
wp_dequeue_script( 'selectWoo' );
wp_dequeue_style( 'select2' );
}

/**
* Register block pattern for Empty Cart Message to make it translatable.
*/
Expand Down Expand Up @@ -147,11 +159,8 @@ protected function enqueue_assets( array $attributes ) {
* @return string Rendered block type output.
*/
protected function render( $attributes, $content, $block ) {
// Deregister core cart scripts and styles.
wp_dequeue_script( 'wc-cart' );
wp_dequeue_script( 'wc-password-strength-meter' );
wp_dequeue_script( 'selectWoo' );
wp_dequeue_style( 'select2' );
// Dequeue the core scripts when rendering this block.
add_action( 'wp_enqueue_scripts', array( $this, 'dequeue_woocommerce_core_scripts' ), 20 );

/**
* We need to check if $content has any templates from prior iterations of the block, in order to update to the latest iteration.
Expand Down
21 changes: 16 additions & 5 deletions src/BlockTypes/Checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ class Checkout extends AbstractBlock {
protected function initialize() {
parent::initialize();
add_action( 'wp_loaded', array( $this, 'register_patterns' ) );

}

/**
* Dequeues the scripts added by WC Core to the Checkout page.
*
* @return void
*/
public function dequeue_woocommerce_core_scripts() {
wp_dequeue_script( 'wc-checkout' );
wp_dequeue_script( 'wc-password-strength-meter' );
wp_dequeue_script( 'selectWoo' );
wp_dequeue_style( 'select2' );
}

/**
Expand Down Expand Up @@ -119,17 +132,15 @@ protected function enqueue_assets( array $attributes ) {
* @return string Rendered block type output.
*/
protected function render( $attributes, $content, $block ) {

if ( $this->is_checkout_endpoint() ) {
// Note: Currently the block only takes care of the main checkout form -- if an endpoint is set, refer to the
// legacy shortcode instead and do not render block.
return wc_current_theme_is_fse_theme() ? do_shortcode( '[woocommerce_checkout]' ) : '[woocommerce_checkout]';
}

// Deregister core checkout scripts and styles.
wp_dequeue_script( 'wc-checkout' );
wp_dequeue_script( 'wc-password-strength-meter' );
wp_dequeue_script( 'selectWoo' );
wp_dequeue_style( 'select2' );
// Dequeue the core scripts when rendering this block.
add_action( 'wp_enqueue_scripts', array( $this, 'dequeue_woocommerce_core_scripts' ), 20 );

/**
* We need to check if $content has any templates from prior iterations of the block, in order to update to the latest iteration.
Expand Down
Loading