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

Commit

Permalink
Fix styling of Classic Cart and Checkout Blocks on regular pages (#11694
Browse files Browse the repository at this point in the history
)

* woocommerce_is_checkout/woocommerce_is_cart for classic shortcode block

* Add return to has_block_variation
  • Loading branch information
mikejolley authored Nov 13, 2023
1 parent 8fc475a commit e3801ba
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/BlockTypesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,46 @@ protected function init() {
add_action( 'woocommerce_login_form_end', array( $this, 'redirect_to_field' ) );
add_filter( 'widget_types_to_hide_from_legacy_widget_block', array( $this, 'hide_legacy_widgets_with_block_equivalent' ) );
add_action( 'woocommerce_delete_product_transients', array( $this, 'delete_product_transients' ) );
add_filter(
'woocommerce_is_checkout',
function( $return ) {
return $return || $this->has_block_variation( 'woocommerce/classic-shortcode', 'shortcode', 'checkout' );
}
);
add_filter(
'woocommerce_is_cart',
function( $return ) {
return $return || $this->has_block_variation( 'woocommerce/classic-shortcode', 'shortcode', 'cart' );
}
);
}

/**
* Check if the current post has a block with a specific attribute value.
*
* @param string $block_id The block ID to check for.
* @param string $attribute The attribute to check.
* @param string $value The value to check for.
* @return boolean
*/
private function has_block_variation( $block_id, $attribute, $value ) {
$post = get_post();

if ( ! $post ) {
return false;
}

if ( has_block( $block_id, $post->ID ) ) {
$blocks = (array) parse_blocks( $post->post_content );

foreach ( $blocks as $block ) {
if ( isset( $block['attrs'][ $attribute ] ) && $value === $block['attrs'][ $attribute ] ) {
return true;
}
}
}

return false;
}

/**
Expand Down

0 comments on commit e3801ba

Please sign in to comment.