Render Checkout on Pay for Order for FSE themes with checkout flow templates (https://github.com/woocommerce/woocommerce-blocks/pull/10076)
* Render Checkout on Pay for Order for FSE themes with checkout flow templates. Few typos corrected * Render Checkout on Pay for Order for FSE themes with checkout flow templates. Few typos corrected * Backup and restore notices so they display on the pay page still * Cache and restore notices during hydration to avoid breaking real notices on pages/shortcodes --------- Co-authored-by: Mike Jolley <mike.jolley@me.com>
This commit is contained in:
parent
25a5737ec7
commit
50aee9846b
|
@ -237,7 +237,14 @@ class Cart extends AbstractBlock {
|
||||||
* Hydrate the cart block with data from the API.
|
* Hydrate the cart block with data from the API.
|
||||||
*/
|
*/
|
||||||
protected function hydrate_from_api() {
|
protected function hydrate_from_api() {
|
||||||
|
// Cache existing notices now, otherwise they are caught by the Cart Controller and converted to exceptions.
|
||||||
|
$old_notices = WC()->session->get( 'wc_notices', array() );
|
||||||
|
wc_clear_notices();
|
||||||
|
|
||||||
$this->asset_data_registry->hydrate_api_request( '/wc/store/v1/cart' );
|
$this->asset_data_registry->hydrate_api_request( '/wc/store/v1/cart' );
|
||||||
|
|
||||||
|
// Restore notices.
|
||||||
|
WC()->session->set( 'wc_notices', $old_notices );
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Register script and style assets for the block type before it is registered.
|
* Register script and style assets for the block type before it is registered.
|
||||||
|
|
|
@ -88,7 +88,7 @@ class Checkout extends AbstractBlock {
|
||||||
if ( $this->is_checkout_endpoint() ) {
|
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
|
// 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.
|
// legacy shortcode instead and do not render block.
|
||||||
return '[woocommerce_checkout]';
|
return wc_current_theme_is_fse_theme() ? do_shortcode( '[woocommerce_checkout]' ) : '[woocommerce_checkout]';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deregister core checkout scripts and styles.
|
// Deregister core checkout scripts and styles.
|
||||||
|
@ -361,17 +361,19 @@ class Checkout extends AbstractBlock {
|
||||||
* Hydrate the checkout block with data from the API.
|
* Hydrate the checkout block with data from the API.
|
||||||
*/
|
*/
|
||||||
protected function hydrate_from_api() {
|
protected function hydrate_from_api() {
|
||||||
|
// Cache existing notices now, otherwise they are caught by the Cart Controller and converted to exceptions.
|
||||||
|
$old_notices = WC()->session->get( 'wc_notices', array() );
|
||||||
|
wc_clear_notices();
|
||||||
|
|
||||||
$this->asset_data_registry->hydrate_api_request( '/wc/store/v1/cart' );
|
$this->asset_data_registry->hydrate_api_request( '/wc/store/v1/cart' );
|
||||||
|
|
||||||
// Print existing notices now, otherwise they are caught by the Cart
|
|
||||||
// Controller and converted to exceptions.
|
|
||||||
wc_print_notices();
|
|
||||||
add_filter( 'woocommerce_store_api_disable_nonce_check', '__return_true' );
|
add_filter( 'woocommerce_store_api_disable_nonce_check', '__return_true' );
|
||||||
|
|
||||||
$rest_preload_api_requests = rest_preload_api_request( [], '/wc/store/v1/checkout' );
|
$rest_preload_api_requests = rest_preload_api_request( [], '/wc/store/v1/checkout' );
|
||||||
$this->asset_data_registry->add( 'checkoutData', $rest_preload_api_requests['/wc/store/v1/checkout']['body'] ?? [] );
|
$this->asset_data_registry->add( 'checkoutData', $rest_preload_api_requests['/wc/store/v1/checkout']['body'] ?? [] );
|
||||||
|
|
||||||
remove_filter( 'woocommerce_store_api_disable_nonce_check', '__return_true' );
|
remove_filter( 'woocommerce_store_api_disable_nonce_check', '__return_true' );
|
||||||
|
|
||||||
|
// Restore notices.
|
||||||
|
WC()->session->set( 'wc_notices', $old_notices );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -36,7 +36,7 @@ class CheckoutTemplate extends AbstractPageTemplate {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* True when viewing the cart page or cart endpoint.
|
* True when viewing the checkout page or checkout endpoint.
|
||||||
*
|
*
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -26,7 +26,7 @@ class OrderConfirmationTemplate extends AbstractPageTemplate {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* True when viewing the cart page or cart endpoint.
|
* True when viewing the Order Received endpoint.
|
||||||
*
|
*
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue