Local pickup rates are always returned regardless of the shipping zone. (https://github.com/woocommerce/woocommerce-blocks/pull/7177)
* local pickup is always returned no matter the zone * wrap filters in feature flags * switch to experimental
This commit is contained in:
parent
085242bbe9
commit
0f57123095
|
@ -134,13 +134,7 @@ class Package {
|
||||||
*
|
*
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
// phpcs:disable Squiz.PHP.CommentedOutCode
|
public function is_feature_plugin_build() {
|
||||||
// phpcs:disable Squiz.Commenting.InlineComment.InvalidEndChar
|
return $this->feature()->is_feature_plugin_build();
|
||||||
// phpcs:disable Squiz.Commenting.InlineComment.SpacingBefore
|
}
|
||||||
// public function is_feature_plugin_build() {
|
|
||||||
// return $this->feature()->is_feature_plugin_build();
|
|
||||||
// }
|
|
||||||
// phpcs:enable Squiz.PHP.CommentedOutCode
|
|
||||||
// phpcs:enable Squiz.Commenting.InlineComment.InvalidEndChar
|
|
||||||
// phpcs:enable Squiz.Commenting.InlineComment.SpacingBefore
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,16 +85,10 @@ class Package {
|
||||||
*
|
*
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
// This function will be kept around but commented out in case we add feature-plugin-specific code in the future.
|
public static function is_feature_plugin_build() {
|
||||||
// phpcs:disable Squiz.PHP.CommentedOutCode
|
return self::get_package()->is_feature_plugin_build();
|
||||||
// phpcs:disable Squiz.Commenting.InlineComment.InvalidEndChar
|
}
|
||||||
// phpcs:disable Squiz.Commenting.InlineComment.SpacingBefore
|
|
||||||
// public static function is_feature_plugin_build() {
|
|
||||||
// return self::get_package()->is_feature_plugin_build();
|
|
||||||
// }
|
|
||||||
// phpcs:enable Squiz.PHP.CommentedOutCode
|
|
||||||
// phpcs:enable Squiz.Commenting.InlineComment.InvalidEndChar
|
|
||||||
// phpcs:enable Squiz.Commenting.InlineComment.SpacingBefore
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads the dependency injection container for woocommerce blocks.
|
* Loads the dependency injection container for woocommerce blocks.
|
||||||
|
|
|
@ -12,6 +12,7 @@ use Automattic\WooCommerce\StoreApi\Utilities\ArrayUtils;
|
||||||
use Automattic\WooCommerce\StoreApi\Utilities\DraftOrderTrait;
|
use Automattic\WooCommerce\StoreApi\Utilities\DraftOrderTrait;
|
||||||
use Automattic\WooCommerce\StoreApi\Utilities\NoticeHandler;
|
use Automattic\WooCommerce\StoreApi\Utilities\NoticeHandler;
|
||||||
use Automattic\WooCommerce\StoreApi\Utilities\QuantityLimits;
|
use Automattic\WooCommerce\StoreApi\Utilities\QuantityLimits;
|
||||||
|
use Automattic\WooCommerce\Blocks\Package;
|
||||||
use WP_Error;
|
use WP_Error;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -787,6 +788,11 @@ class CartController {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( Package::feature()->is_experimental_build() ) {
|
||||||
|
// This is a temporary measure until we can bring such change to WooCommerce core.
|
||||||
|
add_filter( 'woocommerce_get_shipping_methods', [ $this, 'enable_local_pickup_without_address' ] );
|
||||||
|
}
|
||||||
|
|
||||||
$packages = $cart->get_shipping_packages();
|
$packages = $cart->get_shipping_packages();
|
||||||
|
|
||||||
// Add extra package data to array.
|
// Add extra package data to array.
|
||||||
|
@ -803,9 +809,40 @@ class CartController {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $calculate_rates ? wc()->shipping()->calculate_shipping( $packages ) : $packages;
|
$packages = $calculate_rates ? wc()->shipping()->calculate_shipping( $packages ) : $packages;
|
||||||
|
|
||||||
|
if ( Package::feature()->is_experimental_build() ) {
|
||||||
|
// This is a temporary measure until we can bring such change to WooCommerce core.
|
||||||
|
remove_filter( 'woocommerce_get_shipping_methods', [ $this, 'enable_local_pickup_without_address' ] );
|
||||||
|
}
|
||||||
|
|
||||||
|
return $packages;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* We want to make local pickup always avaiable without checking for a shipping zone or address.
|
||||||
|
*
|
||||||
|
* @param array $shipping_methods Package we're checking against right now.
|
||||||
|
* @return array $shipping_methods Shipping methods with local pickup.
|
||||||
|
*/
|
||||||
|
public function enable_local_pickup_without_address( $shipping_methods ) {
|
||||||
|
$shipping_zones = \WC_Shipping_Zones::get_zones( 'admin' );
|
||||||
|
$worldwide_zone = new \WC_Shipping_Zone( 0 );
|
||||||
|
$all_methods = array_map(
|
||||||
|
function( $_shipping_zone ) {
|
||||||
|
return $_shipping_zone['shipping_methods'];
|
||||||
|
},
|
||||||
|
$shipping_zones
|
||||||
|
);
|
||||||
|
$all_methods = array_merge_recursive( $worldwide_zone->get_shipping_methods( false, 'admin' ), ...$all_methods );
|
||||||
|
$local_pickups = array_filter(
|
||||||
|
$all_methods,
|
||||||
|
function( $method ) {
|
||||||
|
return 'local_pickup' === $method->id;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
return array_merge( $shipping_methods, $local_pickups );
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Creates a name for a package.
|
* Creates a name for a package.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue