Automattic\WooCommerce\Blocks
AssetsController::get_prefetch_resource_hints
Get resource hints during prefetch requests.
Method of the class: AssetsController{}
No Hooks.
Returns
Array. Array of URLs.
Usage
// private - for code of main (parent) class only $result = $this->get_prefetch_resource_hints();
AssetsController::get_prefetch_resource_hints() AssetsController::get prefetch resource hints code WC 10.9.1
private function get_prefetch_resource_hints() {
$urls = array();
// Core page IDs.
$cart_page_id = wc_get_page_id( 'cart' );
$checkout_page_id = wc_get_page_id( 'checkout' );
// Checks a specific page (by ID) to see if it contains the named block.
$has_block_cart = $cart_page_id && has_block( 'woocommerce/cart', $cart_page_id );
$has_block_checkout = $checkout_page_id && has_block( 'woocommerce/checkout', $checkout_page_id );
// Checks the current page to see if it contains the named block.
$is_block_cart = has_block( 'woocommerce/cart' );
$is_block_checkout = has_block( 'woocommerce/checkout' );
if ( $has_block_cart && ! $is_block_cart ) {
$urls = array_merge( $urls, $this->get_block_asset_resource_hints( 'cart-frontend' ) );
}
if ( $has_block_checkout && ! $is_block_checkout ) {
$urls = array_merge( $urls, $this->get_block_asset_resource_hints( 'checkout-frontend' ) );
}
return $urls;
}