Automattic\WooCommerce\Blocks\Shipping
ShippingController::hydrate_client_settings()
Hydrate client settings
Method of the class: ShippingController{}
No Hooks.
Return
null
. Nothing (null).
Usage
$ShippingController = new ShippingController(); $ShippingController->hydrate_client_settings();
ShippingController::hydrate_client_settings() ShippingController::hydrate client settings code WC 9.2.3
public function hydrate_client_settings() { $locations = get_option( 'pickup_location_pickup_locations', array() ); $formatted_pickup_locations = array(); foreach ( $locations as $location ) { $formatted_pickup_locations[] = array( 'name' => $location['name'], 'address' => $location['address'], 'details' => $location['details'], 'enabled' => wc_string_to_bool( $location['enabled'] ), ); } $has_legacy_pickup = false; // Get all shipping zones. $shipping_zones = \WC_Shipping_Zones::get_zones( 'admin' ); $international_shipping_zone = new \WC_Shipping_Zone( 0 ); // Loop through each shipping zone. foreach ( $shipping_zones as $shipping_zone ) { // Get all registered rates for this shipping zone. $shipping_methods = $shipping_zone['shipping_methods']; // Loop through each registered rate. foreach ( $shipping_methods as $shipping_method ) { if ( 'local_pickup' === $shipping_method->id && 'yes' === $shipping_method->enabled ) { $has_legacy_pickup = true; break 2; } } } foreach ( $international_shipping_zone->get_shipping_methods( true ) as $shipping_method ) { if ( 'local_pickup' === $shipping_method->id ) { $has_legacy_pickup = true; break; } } $settings = array( 'pickupLocationSettings' => LocalPickupUtils::get_local_pickup_settings(), 'pickupLocations' => $formatted_pickup_locations, 'readonlySettings' => array( 'hasLegacyPickup' => $has_legacy_pickup, 'storeCountry' => WC()->countries->get_base_country(), 'storeState' => WC()->countries->get_base_state(), ), ); wp_add_inline_script( 'wc-shipping-method-pickup-location', sprintf( 'var hydratedScreenSettings = %s;', wp_json_encode( $settings ) ), 'before' ); }