Check for proper currency when getting WCS live rates carrier in setup wizard (#17240)

This commit is contained in:
Paul Dechov 2017-10-18 11:09:33 -04:00 committed by GitHub
parent 2b3f524d35
commit 85af075566
1 changed files with 18 additions and 14 deletions

View File

@ -586,14 +586,15 @@ class WC_Admin_Setup_Wizard {
*
* Can also be used to determine if WCS supports a given country.
*
* @param $country_code
* @param string $country_code
* @param string $currency_code
* @return bool|string Carrier name if supported, boolean False otherwise.
*/
protected function get_wcs_shipping_carrier( $country_code ) {
switch ( $country_code ) {
case 'US':
protected function get_wcs_shipping_carrier( $country_code, $currency_code ) {
switch ( array( $country_code, $currency_code ) ) {
case array( 'US', 'USD' ):
return 'USPS';
case 'CA':
case array( 'CA', 'CAD' ):
return 'Canada Post';
default:
return false;
@ -603,10 +604,11 @@ class WC_Admin_Setup_Wizard {
/**
* Get shipping methods based on country code.
*
* @param $country_code
* @param string $country_code
* @param string $currency_code
* @return array
*/
protected function get_wizard_shipping_methods( $country_code ) {
protected function get_wizard_shipping_methods( $country_code, $currency_code ) {
$shipping_methods = array(
'live_rates' => array(
'name' => __( 'Live Rates', 'woocommerce' ),
@ -630,7 +632,7 @@ class WC_Admin_Setup_Wizard {
),
);
$live_rate_carrier = $this->get_wcs_shipping_carrier( $country_code );
$live_rate_carrier = $this->get_wcs_shipping_carrier( $country_code, $currency_code );
if ( false === $live_rate_carrier || ! current_user_can('install_plugins') ) {
unset( $shipping_methods['live_rates'] );
@ -643,12 +645,13 @@ class WC_Admin_Setup_Wizard {
* Render the available shipping methods for a given country code.
*
* @param string $country_code
* @param string $currency_code
* @param string $input_prefix
*/
protected function shipping_method_selection_form( $country_code, $input_prefix ) {
$live_rate_carrier = $this->get_wcs_shipping_carrier( $country_code );
protected function shipping_method_selection_form( $country_code, $currency_code, $input_prefix ) {
$live_rate_carrier = $this->get_wcs_shipping_carrier( $country_code, $currency_code );
$selected = $live_rate_carrier ? 'live_rates' : 'flat_rate';
$shipping_methods = $this->get_wizard_shipping_methods( $country_code );
$shipping_methods = $this->get_wizard_shipping_methods( $country_code, $currency_code );
?>
<div class="wc-wizard-shipping-method-select">
<div class="wc-wizard-shipping-method-dropdown">
@ -702,7 +705,8 @@ class WC_Admin_Setup_Wizard {
$country_code = WC()->countries->get_base_country();
$country_name = WC()->countries->countries[ $country_code ];
$prefixed_country_name = WC()->countries->estimated_for_prefix( $country_code ) . $country_name;
$wcs_carrier = $this->get_wcs_shipping_carrier( $country_code );
$currency_code = get_woocommerce_currency();
$wcs_carrier = $this->get_wcs_shipping_carrier( $country_code, $currency_code );
$existing_zones = WC_Shipping_Zones::get_zones();
if ( false === $dimension_unit || false === $weight_unit ) {
@ -751,7 +755,7 @@ class WC_Admin_Setup_Wizard {
<p><?php echo esc_html( $country_name ); ?></p>
</div>
<div class="wc-wizard-service-description">
<?php $this->shipping_method_selection_form( $country_code, 'shipping_zones[domestic]' ); ?>
<?php $this->shipping_method_selection_form( $country_code, $currency_code, 'shipping_zones[domestic]' ); ?>
</div>
<div class="wc-wizard-service-enable">
<span class="wc-wizard-service-toggle">
@ -765,7 +769,7 @@ class WC_Admin_Setup_Wizard {
<p><?php echo esc_html_e( 'Locations not covered by your other zones', 'woocommerce' ); ?></p>
</div>
<div class="wc-wizard-service-description">
<?php $this->shipping_method_selection_form( $country_code, 'shipping_zones[intl]' ); ?>
<?php $this->shipping_method_selection_form( $country_code, $currency_code, 'shipping_zones[intl]' ); ?>
</div>
<div class="wc-wizard-service-enable">
<span class="wc-wizard-service-toggle">