Fix block context

This commit is contained in:
Alex P 2023-04-17 10:23:13 +03:00
parent 19f004becd
commit b444c1ef55
No known key found for this signature in database
GPG key ID: 54487A734A204D71

View file

@ -17,33 +17,32 @@ trait ContextTrait {
* @return string * @return string
*/ */
protected function context(): string { protected function context(): string {
$context = 'mini-cart';
if ( is_product() || wc_post_content_has_shortcode( 'product_page' ) ) { if ( is_product() || wc_post_content_has_shortcode( 'product_page' ) ) {
$context = 'product'; return 'product';
} }
// has_block may not work if called too early, such as during the block registration. // has_block may not work if called too early, such as during the block registration.
if ( has_block( 'woocommerce/cart' ) ) { if ( has_block( 'woocommerce/cart' ) ) {
$context = 'cart-block'; return 'cart-block';
} }
if ( is_cart() ) { if ( is_cart() ) {
$context = 'cart'; return 'cart';
} }
if ( has_block( 'woocommerce/checkout' ) ) { if ( has_block( 'woocommerce/checkout' ) ) {
$context = 'checkout-block'; return 'checkout-block';
} }
if ( ( is_checkout() ) && ! $this->is_paypal_continuation() ) { if ( ( is_checkout() ) && ! $this->is_paypal_continuation() ) {
$context = 'checkout'; return 'checkout';
} }
if ( is_checkout_pay_page() ) { if ( is_checkout_pay_page() ) {
$context = 'pay-now'; return 'pay-now';
} }
return $context; return 'mini-cart';
} }
/** /**