Reverts work done in woocommerce/woocommerce-admin#4857 for automated shipping after OBW is completed (https://github.com/woocommerce/woocommerce-admin/pull/5971)
* Reverts work done in woocommerce/woocommerce-admin#4857 for automated shipping after OBW is completed * Remove ReviewShippingSettings note * Update readme.txt * Add wc-admin-review-shipping-settings to delete note list
This commit is contained in:
parent
522c31b454
commit
71877be8dc
|
@ -82,6 +82,7 @@ Release and roadmap notes are available on the [WooCommerce Developers Blog](htt
|
|||
- Fix: Invalidate product count if the last product was updated in the list. #5790
|
||||
- Fix: Updating (non wordpress user) customer with order data
|
||||
- Dev: Add documentation for filter `woocommerce_admin_pages_list` and `wc_admin_register_page` #5844
|
||||
- Dev: Revert work done in #4857 for automated shipping after OBW is completed #5971
|
||||
|
||||
== Changelog ==
|
||||
|
||||
|
|
|
@ -9,7 +9,6 @@ namespace Automattic\WooCommerce\Admin\Features;
|
|||
use \Automattic\WooCommerce\Admin\Loader;
|
||||
use Automattic\WooCommerce\Admin\PageController;
|
||||
use \Automattic\WooCommerce\Admin\PluginsHelper;
|
||||
use \Automattic\WooCommerce\Admin\Features\OnboardingSetUpShipping;
|
||||
|
||||
/**
|
||||
* Contains backend logic for the onboarding profile and checklist feature.
|
||||
|
@ -65,9 +64,6 @@ class Onboarding {
|
|||
// Add actions and filters.
|
||||
$this->add_actions();
|
||||
$this->add_filters();
|
||||
|
||||
// Hook up dependent classes.
|
||||
new OnboardingSetUpShipping();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,149 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Onboarding - set up shipping.
|
||||
*
|
||||
* @package Woocommerce Admin
|
||||
*/
|
||||
|
||||
namespace Automattic\WooCommerce\Admin\Features;
|
||||
|
||||
use \Automattic\WooCommerce\Admin\PluginsHelper;
|
||||
use \Automattic\WooCommerce\Admin\Notes\ReviewShippingSettings;
|
||||
|
||||
/**
|
||||
* This contains logic for setting up shipping when the profiler completes.
|
||||
*/
|
||||
class OnboardingSetUpShipping {
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
add_action(
|
||||
'woocommerce_onboarding_profile_completed',
|
||||
array(
|
||||
__CLASS__,
|
||||
'on_onboarding_profile_completed',
|
||||
)
|
||||
);
|
||||
|
||||
add_action(
|
||||
'jetpack_authorize_ending_authorized',
|
||||
array(
|
||||
__CLASS__,
|
||||
'on_onboarding_profile_completed',
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up shipping.
|
||||
*/
|
||||
public static function on_onboarding_profile_completed() {
|
||||
if ( ! self::has_physical_products() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( self::has_existing_shipping_zones() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$country_code = WC()->countries->get_base_country();
|
||||
|
||||
// Corrolary to the logic in /client/task-list/tasks.js.
|
||||
// Skip for countries we don't recommend WCS for.
|
||||
if ( in_array( $country_code, array( 'AU', 'CA', 'GB' ), true ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
! class_exists( '\Jetpack_Data' ) ||
|
||||
! class_exists( '\WC_Connect_Loader' ) ||
|
||||
! class_exists( '\WC_Connect_Options' )
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( defined( 'JETPACK_MASTER_USER' ) ) {
|
||||
$user_token = \Jetpack_Data::get_access_token( JETPACK_MASTER_USER );
|
||||
$jetpack_connected = isset( $user_token->external_user_id );
|
||||
} else {
|
||||
/**
|
||||
* Filter allowing to set the status of the jetpack connection wiuthout setting constant `JETPACK_MASTER_USER`
|
||||
*
|
||||
* @param bool $is_connected False.
|
||||
*/
|
||||
$jetpack_connected = apply_filters( 'woocommerce_admin_is_jetpack_connected', false );
|
||||
}
|
||||
|
||||
$wcs_version = \WC_Connect_Loader::get_wcs_version();
|
||||
$wcs_tos_accepted = \WC_Connect_Options::get_option( 'tos_accepted' );
|
||||
|
||||
if ( ! $jetpack_connected || ! $wcs_version || ! $wcs_tos_accepted ) {
|
||||
return;
|
||||
}
|
||||
|
||||
self::set_up_free_local_shipping();
|
||||
ReviewShippingSettings::possibly_add_note();
|
||||
wc_admin_record_tracks_event( 'shipping_automatically_set_up' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Are there existing shipping zones?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private static function has_existing_shipping_zones() {
|
||||
$zone_count = count( \WC_Shipping_Zones::get_zones() );
|
||||
|
||||
return $zone_count > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is 'physical' selected as a product type?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private static function has_physical_products() {
|
||||
$onboarding_data = get_option( Onboarding::PROFILE_DATA_OPTION );
|
||||
|
||||
if ( ! isset( $onboarding_data['product_types'] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! in_array( 'physical', $onboarding_data['product_types'], true ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up free local shipping.
|
||||
*/
|
||||
public static function set_up_free_local_shipping() {
|
||||
$default_country = apply_filters(
|
||||
'woocommerce_get_base_location',
|
||||
get_option( 'woocommerce_default_country' )
|
||||
);
|
||||
|
||||
if ( ! $default_country ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$country_code = explode( ':', $default_country )[0];
|
||||
$zone = new \WC_Shipping_Zone();
|
||||
|
||||
$zone->add_location( $country_code, 'country' );
|
||||
|
||||
$countries_service = new \WC_Countries();
|
||||
$countries = $countries_service->get_countries();
|
||||
$zone_name = isset( $countries[ $country_code ] )
|
||||
? $countries[ $country_code ]
|
||||
: $country_code;
|
||||
|
||||
$zone->set_zone_name( $zone_name );
|
||||
|
||||
$zone->save();
|
||||
$zone->add_shipping_method( 'free_shipping' );
|
||||
}
|
||||
}
|
|
@ -478,6 +478,7 @@ class Install {
|
|||
'wc-admin-learn-more-about-product-settings',
|
||||
'wc-admin-onboarding-profiler-reminder',
|
||||
'wc-admin-historical-data',
|
||||
'wc-admin-review-shipping-settings',
|
||||
);
|
||||
|
||||
$additional_obsolete_notes_names = apply_filters(
|
||||
|
|
|
@ -621,27 +621,6 @@ class WC_Admin_Notes_Real_Time_Order_Alerts extends DeprecatedClassFacade {
|
|||
protected static $deprecated_in_version = '1.7.0';
|
||||
}
|
||||
|
||||
/**
|
||||
* WC_Admin_Notes_Review_Shipping_Settings.
|
||||
*
|
||||
* @deprecated since 1.7.0, use ReviewShippingSettings
|
||||
*/
|
||||
class WC_Admin_Notes_Review_Shipping_Settings extends DeprecatedClassFacade {
|
||||
/**
|
||||
* The name of the non-deprecated class that this facade covers.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected static $facade_over_classname = 'Automattic\WooCommerce\Admin\Notes\ReviewShippingSettings';
|
||||
|
||||
/**
|
||||
* The version that this class was deprecated in.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected static $deprecated_in_version = '1.7.0';
|
||||
}
|
||||
|
||||
/**
|
||||
* WC_Admin_Notes_Selling_Online_Courses.
|
||||
*
|
||||
|
|
|
@ -1,60 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* WooCommerce Admin Review Shipping Settings Note Provider.
|
||||
*
|
||||
* Adds an admin note prompting the admin to review their shipping settings.
|
||||
*
|
||||
* @package WooCommerce Admin
|
||||
*/
|
||||
|
||||
namespace Automattic\WooCommerce\Admin\Notes;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Review_Shipping_Settings
|
||||
*/
|
||||
class ReviewShippingSettings {
|
||||
use NoteTraits;
|
||||
|
||||
const NOTE_NAME = 'wc-admin-review-shipping-settings';
|
||||
|
||||
/**
|
||||
* Get the note.
|
||||
*
|
||||
* @return Note
|
||||
*/
|
||||
public static function get_note() {
|
||||
$note = new Note();
|
||||
|
||||
$content_lines = array(
|
||||
__(
|
||||
"Based on the information that you provided we've configured some shipping rates and options for your store:<br/><br/>",
|
||||
'woocommerce-admin'
|
||||
),
|
||||
__( 'Domestic orders: free shipping<br/>', 'woocommerce-admin' ),
|
||||
__( 'International orders: disabled<br/>', 'woocommerce-admin' ),
|
||||
);
|
||||
|
||||
if ( 'US' === WC()->countries->get_base_country() ) {
|
||||
array_push( $content_lines, __( 'Label printing: enabled', 'woocommerce-admin' ) );
|
||||
}
|
||||
|
||||
$note->set_name( self::NOTE_NAME );
|
||||
$note->set_source( 'woocommerce-admin' );
|
||||
$note->set_title( __( 'Review your shipping settings', 'woocommerce-admin' ) );
|
||||
$note->set_content( implode( '', $content_lines ) );
|
||||
$note->set_content_data( (object) array() );
|
||||
$note->set_type( Note::E_WC_ADMIN_NOTE_INFORMATIONAL );
|
||||
|
||||
$note->add_action(
|
||||
'edit-shipping-settings',
|
||||
__( 'Edit shipping settings', 'woocommerce-admin' ),
|
||||
admin_url( 'admin.php?page=wc-settings&tab=shipping' ),
|
||||
Note::E_WC_ADMIN_NOTE_UNACTIONED,
|
||||
true
|
||||
);
|
||||
|
||||
return $note;
|
||||
}
|
||||
}
|
|
@ -1,102 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Onboarding - set up shipping tests.
|
||||
*
|
||||
* @package WooCommerce\Tests\Onboarding-shipping-set-up
|
||||
*/
|
||||
|
||||
use \Automattic\WooCommerce\Admin\Features\OnboardingSetUpShipping;
|
||||
use \Automattic\WooCommerce\Admin\Notes\ReviewShippingSettings;
|
||||
|
||||
/**
|
||||
* Tests shipping set up during onboarding.
|
||||
*/
|
||||
class WC_Tests_OnboardingShippingSetUp extends WC_Unit_Test_Case {
|
||||
/**
|
||||
* Verify that the zone gets created.
|
||||
*/
|
||||
public function test_zone_gets_created_when_setting_up_free_shipping() {
|
||||
update_option( 'woocommerce_default_country', 'AU:QLD' );
|
||||
|
||||
OnboardingSetUpShipping::set_up_free_local_shipping();
|
||||
|
||||
$zones = \WC_Shipping_Zones::get_zones();
|
||||
|
||||
// There should be only one zone, with a zone name of 'Australia'.
|
||||
$this->assertEquals( 1, count( $zones ) );
|
||||
$zone = $zones[ array_keys( $zones )[0] ];
|
||||
$this->assertEquals( 'Australia', $zone['zone_name'] );
|
||||
|
||||
// There should only be one zone location with a code of 'AU'.
|
||||
$this->assertEquals( 1, count( $zone['zone_locations'] ) );
|
||||
$zone_location = $zone['zone_locations'][0];
|
||||
$this->assertEquals( 'AU', $zone_location->code );
|
||||
|
||||
// There should be only one shipping zone method, with a method ID of
|
||||
// 'free_shipping'.
|
||||
$data_store = WC_Data_Store::load( 'shipping-zone' );
|
||||
$methods = $data_store->get_methods( $zone['id'], true );
|
||||
$this->assertEquals( 1, count( $methods ) );
|
||||
$method = $methods[0];
|
||||
$this->assertEquals( 'free_shipping', $method->method_id );
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that the zone doesn't get created if there is no default
|
||||
* country.
|
||||
*/
|
||||
public function test_zone_does_not_get_created_with_no_default_country() {
|
||||
add_filter(
|
||||
'woocommerce_get_base_location',
|
||||
array(
|
||||
$this,
|
||||
'get_empty_base_location',
|
||||
)
|
||||
);
|
||||
|
||||
OnboardingSetUpShipping::set_up_free_local_shipping();
|
||||
|
||||
$zones = \WC_Shipping_Zones::get_zones();
|
||||
|
||||
$this->assertEquals( 0, count( $zones ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get empty base location.
|
||||
*/
|
||||
public function get_empty_base_location() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that the shipping note does not include label printing for non-us countries.
|
||||
* Related issue: https://github.com/woocommerce/woocommerce-admin/issues/5394.
|
||||
*/
|
||||
public function test_shipping_note_does_not_include_label_printing_for_non_us_countries() {
|
||||
// Given AU:QLD as the default country.
|
||||
update_option( 'woocommerce_default_country', 'AU:QLD' );
|
||||
|
||||
// When note is retrieved.
|
||||
$note = ReviewShippingSettings::get_note()->get_content();
|
||||
|
||||
// Then it should not contain 'Label printing: enabled'.
|
||||
$contains_string = strpos( $note, 'Label printing: enabled' );
|
||||
$this->assertFalse( $contains_string );
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that the shipping note includes label printing for US.
|
||||
* Related issue: https://github.com/woocommerce/woocommerce-admin/issues/5394.
|
||||
*/
|
||||
public function test_shipping_note_includes_label_printing_string_for_us() {
|
||||
// Given US:CA as the default country.
|
||||
update_option( 'woocommerce_default_country', 'US:CA' );
|
||||
|
||||
// When note is retrieved.
|
||||
$note = ReviewShippingSettings::get_note()->get_content();
|
||||
|
||||
// Then it should contain 'Label printing: enabled'.
|
||||
$contains_string = strpos( $note, 'Label printing: enabled' );
|
||||
$this->assertNotFalse( $contains_string );
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue