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

Commit d2d809b

Browse files
authored
only load shipping countries when shipping is needed (#6901)
1 parent 1f706c1 commit d2d809b

File tree

2 files changed

+33
-28
lines changed

2 files changed

+33
-28
lines changed

src/BlockTypes/Cart.php

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -155,21 +155,23 @@ protected function render( $attributes, $content ) {
155155
*/
156156
protected function enqueue_data( array $attributes = [] ) {
157157
parent::enqueue_data( $attributes );
158+
if ( wc_shipping_enabled() ) {
159+
$this->asset_data_registry->add(
160+
'shippingCountries',
161+
function() {
162+
return $this->deep_sort_with_accents( WC()->countries->get_shipping_countries() );
163+
},
164+
true
165+
);
166+
$this->asset_data_registry->add(
167+
'shippingStates',
168+
function() {
169+
return $this->deep_sort_with_accents( WC()->countries->get_shipping_country_states() );
170+
},
171+
true
172+
);
173+
}
158174

159-
$this->asset_data_registry->add(
160-
'shippingCountries',
161-
function() {
162-
return $this->deep_sort_with_accents( WC()->countries->get_shipping_countries() );
163-
},
164-
true
165-
);
166-
$this->asset_data_registry->add(
167-
'shippingStates',
168-
function() {
169-
return $this->deep_sort_with_accents( WC()->countries->get_shipping_country_states() );
170-
},
171-
true
172-
);
173175
$this->asset_data_registry->add(
174176
'countryLocale',
175177
function() {

src/BlockTypes/Checkout.php

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -181,20 +181,23 @@ function() {
181181
},
182182
true
183183
);
184-
$this->asset_data_registry->add(
185-
'shippingCountries',
186-
function() {
187-
return $this->deep_sort_with_accents( WC()->countries->get_shipping_countries() );
188-
},
189-
true
190-
);
191-
$this->asset_data_registry->add(
192-
'shippingStates',
193-
function() {
194-
return $this->deep_sort_with_accents( WC()->countries->get_shipping_country_states() );
195-
},
196-
true
197-
);
184+
if ( wc_shipping_enabled() ) {
185+
$this->asset_data_registry->add(
186+
'shippingCountries',
187+
function() {
188+
return $this->deep_sort_with_accents( WC()->countries->get_shipping_countries() );
189+
},
190+
true
191+
);
192+
$this->asset_data_registry->add(
193+
'shippingStates',
194+
function() {
195+
return $this->deep_sort_with_accents( WC()->countries->get_shipping_country_states() );
196+
},
197+
true
198+
);
199+
}
200+
198201
$this->asset_data_registry->add(
199202
'countryLocale',
200203
function() {

0 commit comments

Comments
 (0)