Automattic\WooCommerce\Admin\API
OnboardingProfile::update_store_currency_and_measurement_units()
Update store's currency and measurement units. Requires 'country' code to be passed in the request.
Метод класса: OnboardingProfile{}
Хуков нет.
Возвращает
WP_Error|WP_REST_Response
.
Использование
$OnboardingProfile = new OnboardingProfile(); $OnboardingProfile->update_store_currency_and_measurement_units( $request );
- $request(WP_REST_Request) (обязательный)
- Request data.
Код OnboardingProfile::update_store_currency_and_measurement_units() OnboardingProfile::update store currency and measurement units WC 9.8.2
public function update_store_currency_and_measurement_units( WP_REST_Request $request ) { $country_code = $request->get_param( 'country_code' ); $locale_info = include WC()->plugin_path() . '/i18n/locale-info.php'; if ( empty( $country_code ) || ! isset( $locale_info[ $country_code ] ) ) { return new WP_Error( 'woocommerce_rest_invalid_country_code', __( 'Invalid country code.', 'woocommerce' ), array( 'status' => 400 ) ); } $country_info = $locale_info[ $country_code ]; $currency_settings = array( 'woocommerce_currency' => $country_info['currency_code'], 'woocommerce_currency_pos' => $country_info['currency_pos'], 'woocommerce_price_thousand_sep' => $country_info['thousand_sep'], 'woocommerce_price_decimal_sep' => $country_info['decimal_sep'], 'woocommerce_price_num_decimals' => $country_info['num_decimals'], 'woocommerce_weight_unit' => $country_info['weight_unit'], 'woocommerce_dimension_unit' => $country_info['dimension_unit'], ); foreach ( $currency_settings as $key => $value ) { update_option( $key, $value ); } return new WP_REST_Response( array(), 204 ); }