Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/woocomme.../src/Blocks/Utils
File: CartCheckoutUtils.php
<?php // phpcs:ignore Generic.PHP.RequireStrictTypes.MissingDeclaration
[0] Fix | Delete
namespace Automattic\WooCommerce\Blocks\Utils;
[1] Fix | Delete
[2] Fix | Delete
/**
[3] Fix | Delete
* Class containing utility methods for dealing with the Cart and Checkout blocks.
[4] Fix | Delete
*/
[5] Fix | Delete
class CartCheckoutUtils {
[6] Fix | Delete
/**
[7] Fix | Delete
* Caches if we're on the cart page.
[8] Fix | Delete
*
[9] Fix | Delete
* @var bool
[10] Fix | Delete
*/
[11] Fix | Delete
private static $is_cart_page = null;
[12] Fix | Delete
[13] Fix | Delete
/**
[14] Fix | Delete
* Caches if we're on the checkout page.
[15] Fix | Delete
*
[16] Fix | Delete
* @var bool
[17] Fix | Delete
*/
[18] Fix | Delete
private static $is_checkout_page = null;
[19] Fix | Delete
[20] Fix | Delete
/**
[21] Fix | Delete
* Returns true if the current page is a specific page type (cart or checkout).
[22] Fix | Delete
*
[23] Fix | Delete
* This is determined by looking at the global $post object and comparing it to the post ID defined in settings,
[24] Fix | Delete
* or checking the page contents for a block or shortcode.
[25] Fix | Delete
*
[26] Fix | Delete
* This function cannot be used accurately before the `pre_get_posts` action has been run.
[27] Fix | Delete
*
[28] Fix | Delete
* @param string $page_type The page type to check for.
[29] Fix | Delete
* @return bool|null
[30] Fix | Delete
*/
[31] Fix | Delete
private static function is_page_type( string $page_type ): ?bool {
[32] Fix | Delete
if ( ! did_action( 'pre_get_posts' ) ) {
[33] Fix | Delete
return null;
[34] Fix | Delete
}
[35] Fix | Delete
[36] Fix | Delete
$page_id = wc_get_page_id( $page_type );
[37] Fix | Delete
[38] Fix | Delete
if ( $page_id && is_page( $page_id ) ) {
[39] Fix | Delete
return true;
[40] Fix | Delete
}
[41] Fix | Delete
[42] Fix | Delete
// If the is_page check returned false, check the page contents for a cart block or shortcode.
[43] Fix | Delete
global $post;
[44] Fix | Delete
[45] Fix | Delete
if ( null === $post ) {
[46] Fix | Delete
return null;
[47] Fix | Delete
}
[48] Fix | Delete
[49] Fix | Delete
if ( $post instanceof \WP_Post ) {
[50] Fix | Delete
return wc_post_content_has_shortcode( 'cart' === $page_type ? 'woocommerce_cart' : 'woocommerce_checkout' ) || self::has_block_variation( 'woocommerce/classic-shortcode', 'shortcode', $page_type, $post->post_content );
[51] Fix | Delete
}
[52] Fix | Delete
[53] Fix | Delete
return false;
[54] Fix | Delete
}
[55] Fix | Delete
[56] Fix | Delete
/**
[57] Fix | Delete
* Returns true on the cart page.
[58] Fix | Delete
*
[59] Fix | Delete
* @return bool
[60] Fix | Delete
*/
[61] Fix | Delete
public static function is_cart_page(): bool {
[62] Fix | Delete
if ( null === self::$is_cart_page ) {
[63] Fix | Delete
self::$is_cart_page = self::is_page_type( 'cart' );
[64] Fix | Delete
}
[65] Fix | Delete
return true === self::$is_cart_page;
[66] Fix | Delete
}
[67] Fix | Delete
[68] Fix | Delete
/**
[69] Fix | Delete
* Returns true on the checkout page.
[70] Fix | Delete
*
[71] Fix | Delete
* @return bool
[72] Fix | Delete
*/
[73] Fix | Delete
public static function is_checkout_page(): bool {
[74] Fix | Delete
if ( null === self::$is_checkout_page ) {
[75] Fix | Delete
self::$is_checkout_page = self::is_page_type( 'checkout' );
[76] Fix | Delete
}
[77] Fix | Delete
return true === self::$is_checkout_page;
[78] Fix | Delete
}
[79] Fix | Delete
[80] Fix | Delete
/**
[81] Fix | Delete
* Returns true if shipping methods exist in the store. Excludes local pickup and only counts enabled shipping methods.
[82] Fix | Delete
*
[83] Fix | Delete
* @return bool true if shipping methods exist.
[84] Fix | Delete
*/
[85] Fix | Delete
public static function shipping_methods_exist() {
[86] Fix | Delete
// Local pickup is included with legacy shipping methods since they do not support shipping zones.
[87] Fix | Delete
$local_pickup_count = count(
[88] Fix | Delete
array_filter(
[89] Fix | Delete
WC()->shipping()->get_shipping_methods(),
[90] Fix | Delete
function ( $method ) {
[91] Fix | Delete
return isset( $method->enabled ) && 'yes' === $method->enabled && ! $method->supports( 'shipping-zones' ) && $method->supports( 'local-pickup' );
[92] Fix | Delete
}
[93] Fix | Delete
)
[94] Fix | Delete
);
[95] Fix | Delete
[96] Fix | Delete
$shipping_methods_count = wc_get_shipping_method_count( true, true ) - $local_pickup_count;
[97] Fix | Delete
return $shipping_methods_count > 0;
[98] Fix | Delete
}
[99] Fix | Delete
[100] Fix | Delete
/**
[101] Fix | Delete
* Check if the post content contains a block with a specific attribute value.
[102] Fix | Delete
*
[103] Fix | Delete
* @param string $block_id The block ID to check for.
[104] Fix | Delete
* @param string $attribute The attribute to check.
[105] Fix | Delete
* @param string $value The value to check for.
[106] Fix | Delete
* @param string $post_content The post content to check.
[107] Fix | Delete
* @return boolean
[108] Fix | Delete
*/
[109] Fix | Delete
public static function has_block_variation( $block_id, $attribute, $value, $post_content ) {
[110] Fix | Delete
if ( ! $post_content ) {
[111] Fix | Delete
return false;
[112] Fix | Delete
}
[113] Fix | Delete
[114] Fix | Delete
if ( has_block( $block_id, $post_content ) ) {
[115] Fix | Delete
$blocks = (array) parse_blocks( $post_content );
[116] Fix | Delete
[117] Fix | Delete
foreach ( $blocks as $block ) {
[118] Fix | Delete
$block_name = $block['blockName'] ?? '';
[119] Fix | Delete
[120] Fix | Delete
if ( $block_name !== $block_id ) {
[121] Fix | Delete
continue;
[122] Fix | Delete
}
[123] Fix | Delete
[124] Fix | Delete
if ( isset( $block['attrs'][ $attribute ] ) && $value === $block['attrs'][ $attribute ] ) {
[125] Fix | Delete
return true;
[126] Fix | Delete
}
[127] Fix | Delete
[128] Fix | Delete
// `Cart` is default for `woocommerce/classic-shortcode` so it will be empty in the block attributes.
[129] Fix | Delete
if ( 'woocommerce/classic-shortcode' === $block_id && 'shortcode' === $attribute && 'cart' === $value && ! isset( $block['attrs']['shortcode'] ) ) {
[130] Fix | Delete
return true;
[131] Fix | Delete
}
[132] Fix | Delete
}
[133] Fix | Delete
}
[134] Fix | Delete
[135] Fix | Delete
return false;
[136] Fix | Delete
}
[137] Fix | Delete
[138] Fix | Delete
/**
[139] Fix | Delete
* Checks if the default cart page is using the Cart block.
[140] Fix | Delete
*
[141] Fix | Delete
* @return bool true if the WC cart page is using the Cart block.
[142] Fix | Delete
*/
[143] Fix | Delete
public static function is_cart_block_default() {
[144] Fix | Delete
if ( wp_is_block_theme() ) {
[145] Fix | Delete
// Ignore the pages and check the templates.
[146] Fix | Delete
$templates_from_db = BlockTemplateUtils::get_block_templates_from_db( array( 'cart' ), 'wp_template' );
[147] Fix | Delete
foreach ( $templates_from_db as $template ) {
[148] Fix | Delete
if ( has_block( 'woocommerce/cart', $template->content ) ) {
[149] Fix | Delete
return true;
[150] Fix | Delete
}
[151] Fix | Delete
}
[152] Fix | Delete
}
[153] Fix | Delete
$cart_page_id = wc_get_page_id( 'cart' );
[154] Fix | Delete
return $cart_page_id && has_block( 'woocommerce/cart', $cart_page_id );
[155] Fix | Delete
}
[156] Fix | Delete
[157] Fix | Delete
/**
[158] Fix | Delete
* Checks if the default checkout page is using the Checkout block.
[159] Fix | Delete
*
[160] Fix | Delete
* @return bool true if the WC checkout page is using the Checkout block.
[161] Fix | Delete
*/
[162] Fix | Delete
public static function is_checkout_block_default() {
[163] Fix | Delete
if ( wp_is_block_theme() ) {
[164] Fix | Delete
// Ignore the pages and check the templates.
[165] Fix | Delete
$templates_from_db = BlockTemplateUtils::get_block_templates_from_db( array( 'checkout' ), 'wp_template' );
[166] Fix | Delete
foreach ( $templates_from_db as $template ) {
[167] Fix | Delete
if ( has_block( 'woocommerce/checkout', $template->content ) ) {
[168] Fix | Delete
return true;
[169] Fix | Delete
}
[170] Fix | Delete
}
[171] Fix | Delete
}
[172] Fix | Delete
$checkout_page_id = wc_get_page_id( 'checkout' );
[173] Fix | Delete
return $checkout_page_id && has_block( 'woocommerce/checkout', $checkout_page_id );
[174] Fix | Delete
}
[175] Fix | Delete
[176] Fix | Delete
/**
[177] Fix | Delete
* Migrate checkout block field visibility attributes to settings when using the checkout block.
[178] Fix | Delete
*
[179] Fix | Delete
* This migration routine is called if the options (woocommerce_checkout_phone_field, woocommerce_checkout_company_field,
[180] Fix | Delete
* woocommerce_checkout_address_2_field) are not set. They are not set by default; they were orignally set by the
[181] Fix | Delete
* customizer interface of the legacy shortcode based checkout.
[182] Fix | Delete
*
[183] Fix | Delete
* Once migration is initiated, the settings will be updated and will not trigger this routine again.
[184] Fix | Delete
*
[185] Fix | Delete
* Note: The block only stores non-default attributes. Not all attributes will be present.
[186] Fix | Delete
*
[187] Fix | Delete
* e.g. `{"showCompanyField":true,"requireCompanyField":true,"showApartmentField":false,"className":"wc-block-checkout"}`
[188] Fix | Delete
*
[189] Fix | Delete
* If the attributes are missing, we assume default values are needed.
[190] Fix | Delete
*/
[191] Fix | Delete
protected static function migrate_checkout_block_field_visibility_attributes() {
[192] Fix | Delete
// Before migrating attributes, migrate the "default" options checkout block uses into the settings.
[193] Fix | Delete
update_option( 'woocommerce_checkout_phone_field', 'optional' );
[194] Fix | Delete
update_option( 'woocommerce_checkout_company_field', 'hidden' );
[195] Fix | Delete
update_option( 'woocommerce_checkout_address_2_field', 'optional' );
[196] Fix | Delete
[197] Fix | Delete
// Parse the block from the checkout page.
[198] Fix | Delete
$checkout_blocks = \WC_Blocks_Utils::get_blocks_from_page( 'woocommerce/checkout', 'checkout' );
[199] Fix | Delete
[200] Fix | Delete
if ( empty( $checkout_blocks ) || ! isset( $checkout_blocks[0]['attrs'] ) ) {
[201] Fix | Delete
return;
[202] Fix | Delete
}
[203] Fix | Delete
[204] Fix | Delete
// Combine actual attributes with default values.
[205] Fix | Delete
$block_attributes = wp_parse_args(
[206] Fix | Delete
$checkout_blocks[0]['attrs'],
[207] Fix | Delete
array(
[208] Fix | Delete
'showPhoneField' => true,
[209] Fix | Delete
'requirePhoneField' => false,
[210] Fix | Delete
'showCompanyField' => false,
[211] Fix | Delete
'requireCompanyField' => false,
[212] Fix | Delete
'showApartmentField' => true,
[213] Fix | Delete
'requireApartmentField' => false,
[214] Fix | Delete
)
[215] Fix | Delete
);
[216] Fix | Delete
[217] Fix | Delete
if ( $block_attributes['showPhoneField'] ) {
[218] Fix | Delete
update_option( 'woocommerce_checkout_phone_field', $block_attributes['requirePhoneField'] ? 'required' : 'optional' );
[219] Fix | Delete
} else {
[220] Fix | Delete
update_option( 'woocommerce_checkout_phone_field', 'hidden' );
[221] Fix | Delete
}
[222] Fix | Delete
[223] Fix | Delete
if ( $block_attributes['showCompanyField'] ) {
[224] Fix | Delete
update_option( 'woocommerce_checkout_company_field', $block_attributes['requireCompanyField'] ? 'required' : 'optional' );
[225] Fix | Delete
} else {
[226] Fix | Delete
update_option( 'woocommerce_checkout_company_field', 'hidden' );
[227] Fix | Delete
}
[228] Fix | Delete
[229] Fix | Delete
if ( $block_attributes['showApartmentField'] ) {
[230] Fix | Delete
update_option( 'woocommerce_checkout_address_2_field', $block_attributes['requireApartmentField'] ? 'required' : 'optional' );
[231] Fix | Delete
} else {
[232] Fix | Delete
update_option( 'woocommerce_checkout_address_2_field', 'hidden' );
[233] Fix | Delete
}
[234] Fix | Delete
}
[235] Fix | Delete
[236] Fix | Delete
/**
[237] Fix | Delete
* Get the default visibility for the address_2 field.
[238] Fix | Delete
*
[239] Fix | Delete
* @return string
[240] Fix | Delete
*/
[241] Fix | Delete
public static function get_company_field_visibility() {
[242] Fix | Delete
$option_value = get_option( 'woocommerce_checkout_company_field' );
[243] Fix | Delete
[244] Fix | Delete
if ( $option_value ) {
[245] Fix | Delete
return $option_value;
[246] Fix | Delete
}
[247] Fix | Delete
[248] Fix | Delete
if ( self::is_checkout_block_default() ) {
[249] Fix | Delete
self::migrate_checkout_block_field_visibility_attributes();
[250] Fix | Delete
return get_option( 'woocommerce_checkout_company_field', 'hidden' );
[251] Fix | Delete
}
[252] Fix | Delete
[253] Fix | Delete
return 'optional';
[254] Fix | Delete
}
[255] Fix | Delete
[256] Fix | Delete
/**
[257] Fix | Delete
* Get the default visibility for the address_2 field.
[258] Fix | Delete
*
[259] Fix | Delete
* @return string
[260] Fix | Delete
*/
[261] Fix | Delete
public static function get_address_2_field_visibility() {
[262] Fix | Delete
$option_value = get_option( 'woocommerce_checkout_address_2_field' );
[263] Fix | Delete
[264] Fix | Delete
if ( $option_value ) {
[265] Fix | Delete
return $option_value;
[266] Fix | Delete
}
[267] Fix | Delete
[268] Fix | Delete
if ( self::is_checkout_block_default() ) {
[269] Fix | Delete
self::migrate_checkout_block_field_visibility_attributes();
[270] Fix | Delete
return get_option( 'woocommerce_checkout_address_2_field', 'optional' );
[271] Fix | Delete
}
[272] Fix | Delete
[273] Fix | Delete
return 'optional';
[274] Fix | Delete
}
[275] Fix | Delete
[276] Fix | Delete
/**
[277] Fix | Delete
* Get the default visibility for the address_2 field.
[278] Fix | Delete
*
[279] Fix | Delete
* @return string
[280] Fix | Delete
*/
[281] Fix | Delete
public static function get_phone_field_visibility() {
[282] Fix | Delete
$option_value = get_option( 'woocommerce_checkout_phone_field' );
[283] Fix | Delete
[284] Fix | Delete
if ( $option_value ) {
[285] Fix | Delete
return $option_value;
[286] Fix | Delete
}
[287] Fix | Delete
[288] Fix | Delete
if ( self::is_checkout_block_default() ) {
[289] Fix | Delete
self::migrate_checkout_block_field_visibility_attributes();
[290] Fix | Delete
return get_option( 'woocommerce_checkout_phone_field', 'optional' );
[291] Fix | Delete
}
[292] Fix | Delete
[293] Fix | Delete
return 'required';
[294] Fix | Delete
}
[295] Fix | Delete
[296] Fix | Delete
/**
[297] Fix | Delete
* Checks if the template overriding the page loads the page content or not.
[298] Fix | Delete
* Templates by default load the page content, but if that block is deleted the content can get out of sync with the one presented in the page editor.
[299] Fix | Delete
*
[300] Fix | Delete
* @param string $block The block to check.
[301] Fix | Delete
*
[302] Fix | Delete
* @return bool true if the template has out of sync content.
[303] Fix | Delete
*/
[304] Fix | Delete
public static function is_overriden_by_custom_template_content( string $block ): bool {
[305] Fix | Delete
[306] Fix | Delete
$block = str_replace( 'woocommerce/', '', $block );
[307] Fix | Delete
[308] Fix | Delete
if ( wp_is_block_theme() ) {
[309] Fix | Delete
$templates_from_db = BlockTemplateUtils::get_block_templates_from_db( array( 'page-' . $block ) );
[310] Fix | Delete
foreach ( $templates_from_db as $template ) {
[311] Fix | Delete
if ( ! has_block( 'woocommerce/page-content-wrapper', $template->content ) ) {
[312] Fix | Delete
// Return true if the template does not load the page content via the woocommerce/page-content-wrapper block.
[313] Fix | Delete
return true;
[314] Fix | Delete
}
[315] Fix | Delete
}
[316] Fix | Delete
}
[317] Fix | Delete
[318] Fix | Delete
return false;
[319] Fix | Delete
}
[320] Fix | Delete
[321] Fix | Delete
/**
[322] Fix | Delete
* Gets country codes, names, states, and locale information.
[323] Fix | Delete
*
[324] Fix | Delete
* @return array
[325] Fix | Delete
*/
[326] Fix | Delete
public static function get_country_data() {
[327] Fix | Delete
$billing_countries = WC()->countries->get_allowed_countries();
[328] Fix | Delete
$shipping_countries = WC()->countries->get_shipping_countries();
[329] Fix | Delete
$country_states = wc()->countries->get_states();
[330] Fix | Delete
$all_countries = self::deep_sort_with_accents( array_unique( array_merge( $billing_countries, $shipping_countries ) ) );
[331] Fix | Delete
$country_locales = array_map(
[332] Fix | Delete
function ( $locale ) {
[333] Fix | Delete
foreach ( $locale as $field => $field_data ) {
[334] Fix | Delete
if ( isset( $field_data['priority'] ) ) {
[335] Fix | Delete
$locale[ $field ]['index'] = $field_data['priority'];
[336] Fix | Delete
unset( $locale[ $field ]['priority'] );
[337] Fix | Delete
}
[338] Fix | Delete
if ( isset( $field_data['class'] ) ) {
[339] Fix | Delete
unset( $locale[ $field ]['class'] );
[340] Fix | Delete
}
[341] Fix | Delete
}
[342] Fix | Delete
return $locale;
[343] Fix | Delete
},
[344] Fix | Delete
WC()->countries->get_country_locale()
[345] Fix | Delete
);
[346] Fix | Delete
[347] Fix | Delete
$country_data = [];
[348] Fix | Delete
[349] Fix | Delete
foreach ( array_keys( $all_countries ) as $country_code ) {
[350] Fix | Delete
$country_data[ $country_code ] = [
[351] Fix | Delete
'allowBilling' => isset( $billing_countries[ $country_code ] ),
[352] Fix | Delete
'allowShipping' => isset( $shipping_countries[ $country_code ] ),
[353] Fix | Delete
'states' => $country_states[ $country_code ] ?? [],
[354] Fix | Delete
'locale' => $country_locales[ $country_code ] ?? [],
[355] Fix | Delete
];
[356] Fix | Delete
}
[357] Fix | Delete
[358] Fix | Delete
return $country_data;
[359] Fix | Delete
}
[360] Fix | Delete
[361] Fix | Delete
/**
[362] Fix | Delete
* Removes accents from an array of values, sorts by the values, then returns the original array values sorted.
[363] Fix | Delete
*
[364] Fix | Delete
* @param array $sort_array Array of values to sort.
[365] Fix | Delete
* @return array Sorted array.
[366] Fix | Delete
*/
[367] Fix | Delete
protected static function deep_sort_with_accents( $sort_array ) {
[368] Fix | Delete
if ( ! is_array( $sort_array ) || empty( $sort_array ) ) {
[369] Fix | Delete
return $sort_array;
[370] Fix | Delete
}
[371] Fix | Delete
[372] Fix | Delete
$array_without_accents = array_map(
[373] Fix | Delete
function ( $value ) {
[374] Fix | Delete
return is_array( $value )
[375] Fix | Delete
? self::deep_sort_with_accents( $value )
[376] Fix | Delete
: remove_accents( wc_strtolower( html_entity_decode( $value ) ) );
[377] Fix | Delete
},
[378] Fix | Delete
$sort_array
[379] Fix | Delete
);
[380] Fix | Delete
[381] Fix | Delete
asort( $array_without_accents );
[382] Fix | Delete
return array_replace( $array_without_accents, $sort_array );
[383] Fix | Delete
}
[384] Fix | Delete
[385] Fix | Delete
/**
[386] Fix | Delete
* Retrieves formatted shipping zones from WooCommerce.
[387] Fix | Delete
*
[388] Fix | Delete
* @return array An array of formatted shipping zones.
[389] Fix | Delete
*/
[390] Fix | Delete
public static function get_shipping_zones() {
[391] Fix | Delete
$shipping_zones = \WC_Shipping_Zones::get_zones();
[392] Fix | Delete
$formatted_shipping_zones = array_reduce(
[393] Fix | Delete
$shipping_zones,
[394] Fix | Delete
function ( $acc, $zone ) {
[395] Fix | Delete
$acc[] = [
[396] Fix | Delete
'id' => $zone['id'],
[397] Fix | Delete
'title' => $zone['zone_name'],
[398] Fix | Delete
'description' => $zone['formatted_zone_location'],
[399] Fix | Delete
];
[400] Fix | Delete
return $acc;
[401] Fix | Delete
},
[402] Fix | Delete
[]
[403] Fix | Delete
);
[404] Fix | Delete
$formatted_shipping_zones[] = [
[405] Fix | Delete
'id' => 0,
[406] Fix | Delete
'title' => __( 'International', 'woocommerce' ),
[407] Fix | Delete
'description' => __( 'Locations outside all other zones', 'woocommerce' ),
[408] Fix | Delete
];
[409] Fix | Delete
return $formatted_shipping_zones;
[410] Fix | Delete
}
[411] Fix | Delete
[412] Fix | Delete
/**
[413] Fix | Delete
* Recursively search the checkout block to find the express checkout block and
[414] Fix | Delete
* get the button style attributes
[415] Fix | Delete
*
[416] Fix | Delete
* @param array $blocks Blocks to search.
[417] Fix | Delete
* @param string $cart_or_checkout The block type to check.
[418] Fix | Delete
*/
[419] Fix | Delete
public static function find_express_checkout_attributes( $blocks, $cart_or_checkout ) {
[420] Fix | Delete
$express_block_name = 'woocommerce/' . $cart_or_checkout . '-express-payment-block';
[421] Fix | Delete
foreach ( $blocks as $block ) {
[422] Fix | Delete
if ( ! empty( $block['blockName'] ) && $express_block_name === $block['blockName'] && ! empty( $block['attrs'] ) ) {
[423] Fix | Delete
return $block['attrs'];
[424] Fix | Delete
}
[425] Fix | Delete
[426] Fix | Delete
if ( ! empty( $block['innerBlocks'] ) ) {
[427] Fix | Delete
$answer = self::find_express_checkout_attributes( $block['innerBlocks'], $cart_or_checkout );
[428] Fix | Delete
if ( $answer ) {
[429] Fix | Delete
return $answer;
[430] Fix | Delete
}
[431] Fix | Delete
}
[432] Fix | Delete
}
[433] Fix | Delete
}
[434] Fix | Delete
[435] Fix | Delete
/**
[436] Fix | Delete
* Given an array of blocks, find the express payment block and update its attributes.
[437] Fix | Delete
*
[438] Fix | Delete
* @param array $blocks Blocks to search.
[439] Fix | Delete
* @param string $cart_or_checkout The block type to check.
[440] Fix | Delete
* @param array $updated_attrs The new attributes to set.
[441] Fix | Delete
*/
[442] Fix | Delete
public static function update_blocks_with_new_attrs( &$blocks, $cart_or_checkout, $updated_attrs ) {
[443] Fix | Delete
$express_block_name = 'woocommerce/' . $cart_or_checkout . '-express-payment-block';
[444] Fix | Delete
foreach ( $blocks as $key => &$block ) {
[445] Fix | Delete
if ( ! empty( $block['blockName'] ) && $express_block_name === $block['blockName'] ) {
[446] Fix | Delete
$blocks[ $key ]['attrs'] = $updated_attrs;
[447] Fix | Delete
}
[448] Fix | Delete
[449] Fix | Delete
if ( ! empty( $block['innerBlocks'] ) ) {
[450] Fix | Delete
self::update_blocks_with_new_attrs( $block['innerBlocks'], $cart_or_checkout, $updated_attrs );
[451] Fix | Delete
}
[452] Fix | Delete
}
[453] Fix | Delete
}
[454] Fix | Delete
[455] Fix | Delete
/**
[456] Fix | Delete
* Check if the cart page is defined.
[457] Fix | Delete
*
[458] Fix | Delete
* @return bool True if the cart page is defined, false otherwise.
[459] Fix | Delete
*/
[460] Fix | Delete
public static function has_cart_page() {
[461] Fix | Delete
return wc_get_page_permalink( 'cart', -1 ) !== -1;
[462] Fix | Delete
}
[463] Fix | Delete
}
[464] Fix | Delete
[465] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function