diff --git a/src/MerchantCenter/MerchantCenterService.php b/src/MerchantCenter/MerchantCenterService.php index a84dd76bbc..1a46c5a10b 100644 --- a/src/MerchantCenter/MerchantCenterService.php +++ b/src/MerchantCenter/MerchantCenterService.php @@ -4,6 +4,8 @@ namespace Automattic\WooCommerce\GoogleListingsAndAds\MerchantCenter; use Automattic\WooCommerce\GoogleListingsAndAds\API\Google\Settings; +use Automattic\WooCommerce\GoogleListingsAndAds\DB\Query\ShippingRateQuery; +use Automattic\WooCommerce\GoogleListingsAndAds\DB\Query\ShippingTimeQuery; use Automattic\WooCommerce\GoogleListingsAndAds\DB\Table\MerchantIssueTable; use Automattic\WooCommerce\GoogleListingsAndAds\DB\Table\ShippingRateTable; use Automattic\WooCommerce\GoogleListingsAndAds\DB\Table\ShippingTimeTable; @@ -137,7 +139,7 @@ public function is_contact_information_setup(): bool { return true; } - // Additional check for users that have already gone through onboarding. + // Additional check for users that have already gone through on-boarding. if ( $this->is_setup_complete() ) { $is_mc_setup = $this->is_mc_contact_information_setup(); $this->options->update( OptionsInterface::CONTACT_INFO_SETUP, $is_mc_setup ); @@ -220,6 +222,10 @@ public function get_setup_status(): array { if ( $this->saved_target_audience() ) { $step = 'shipping_and_taxes'; + + if ( $this->saved_shipping_and_tax_options() ) { + $step = 'store_requirements'; + } } } @@ -334,4 +340,43 @@ protected function is_mc_contact_information_setup(): bool { return $is_setup['phone_number'] && $is_setup['address']; } + + /** + * Check if the taxes + shipping rate and time + free shipping settings have been saved. + * + * @return bool If all required settings have been provided. + * + * @since x.x.x + */ + protected function saved_shipping_and_tax_options(): bool { + $merchant_center_settings = $this->options->get( OptionsInterface::MERCHANT_CENTER, [] ); + $target_countries = $this->get_target_countries(); + + // Tax options saved if: not US (no taxes) or tax_rate has been set + if ( in_array( 'US', $target_countries, true ) && empty( $merchant_center_settings['tax_rate'] ) ) { + return false; + } + + // Free shipping saved if: not offered, OR offered and threshold not null + if ( ! empty( $merchant_center_settings['offers_free_shipping'] ) && ! isset( $merchant_center_settings['free_shipping_threshold'] ) ) { + return false; + } + + // Shipping options saved if: 'manual' OR records for all countries + if ( isset( $merchant_center_settings['shipping_time'] ) && 'manual' === $merchant_center_settings['shipping_time'] ) { + $saved_shipping_time = true; + } else { + $shipping_time_rows = $this->container->get( ShippingTimeQuery::class )->get_count(); + $saved_shipping_time = $shipping_time_rows === count( $target_countries ); + } + + if ( isset( $merchant_center_settings['shipping_rate'] ) && 'manual' === $merchant_center_settings['shipping_rate'] ) { + $saved_shipping_rate = true; + } else { + $shipping_rate_rows = $this->container->get( ShippingRateQuery::class )->get_count(); + $saved_shipping_rate = $shipping_rate_rows === count( $target_countries ); + } + + return $saved_shipping_rate && $saved_shipping_time; + } }