Improve local pickup flow (#45614)

* Update shipping calculation copy

* Update shipping calculation copy

* Update shipping calculation copy

* Update legacy local pickup copy

* Remove ‘target="_blank"’ and ‘rel="noopener noreferrer"’

* WIP: Conditional message and display of legacy local pickup option

* Make util function static

* Make texts translatable

* Add changefile(s) from automation for the following project(s): woocommerce-blocks, woocommerce

* Fix PHPCS errors

* Fix PHPCS errors

* Update plugins/woocommerce/includes/class-wc-shipping.php

Co-authored-by: Gerhard Potgieter <potgieterg@gmail.com>

* Remove duplicate helper method

* Improve helper method

* Replace “esc_html__” with “wp_kses” to keep URL clickable

* Optimise is_legacy_local_pickup_active() method

* Adjust CSS definitions

* Refactor is_cart_block_default() and is_checkout_block_default()

* Ensure that Rest of the World shipping methods are available

* Remove obsolete space

* Adjust text spacing

---------

Co-authored-by: github-actions <github-actions@github.com>
Co-authored-by: Gerhard Potgieter <potgieterg@gmail.com>
This commit is contained in:
Niels Lange 2024-03-20 21:54:12 +07:00 committed by GitHub
parent f1dd1e02a6
commit be63107c92
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 82 additions and 21 deletions

View File

@ -59,7 +59,7 @@ const GeneralSettings = () => {
<StyledNotice status="warning" isDismissible={ false }>
{ createInterpolateElement(
__(
'Enabling this will produce duplicate options at checkout. Remove the local pickup shipping method from your <a>shipping zones</a>.',
"By enabling Local Pickup with more valuable features for your store, it's recommended that you remove the legacy Local Pickup option from your <a>shipping zones</a>.",
'woocommerce'
),
{
@ -67,8 +67,6 @@ const GeneralSettings = () => {
// eslint-disable-next-line jsx-a11y/anchor-has-content
<a
href={ `${ ADMIN_URL }admin.php?page=wc-settings&tab=shipping` }
target="_blank"
rel="noopener noreferrer"
/>
),
}

View File

@ -0,0 +1,4 @@
Significance: minor
Type: update
Improve messages around the use of the legacy and the new Local Pickup shipping methods.

View File

@ -4275,8 +4275,8 @@ table.wc_shipping {
}
}
.wc-shipping-zone-method-input-help-text-container {
min-height: 40px;
.wc-shipping-legacy-local-pickup-help-text-container {
margin: 1.5em 0;
}
.wc-shipping-zone-method-input-help-text {

View File

@ -5,6 +5,9 @@
* @package WooCommerce\Admin\Shipping
*/
use Automattic\WooCommerce\Blocks\Utils\CartCheckoutUtils;
use Automattic\WooCommerce\Blocks\Shipping\ShippingController;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
@ -15,7 +18,10 @@ if ( ! defined( 'ABSPATH' ) ) {
<span class="wc-shipping-zone-name"><?php echo esc_html( $zone->get_zone_name() ? $zone->get_zone_name() : __( 'Zone', 'woocommerce' ) ); ?></span>
</h2>
<?php do_action( 'woocommerce_shipping_zone_before_methods_table', $zone ); ?>
<?php
// phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingHookComment
do_action( 'woocommerce_shipping_zone_before_methods_table', $zone );
?>
<table class="form-table wc-shipping-zone-settings">
<tbody>
@ -90,7 +96,10 @@ if ( ! defined( 'ABSPATH' ) ) {
</tbody>
</table>
<?php do_action( 'woocommerce_shipping_zone_after_methods_table', $zone ); ?>
<?php
// phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingHookComment
do_action( 'woocommerce_shipping_zone_after_methods_table', $zone );
?>
<p class="submit">
<button type="submit" name="submit" id="submit" class="button button-primary button-large wc-shipping-zone-method-save" value="<?php esc_attr_e( 'Save changes', 'woocommerce' ); ?>" disabled><?php esc_html_e( 'Save changes', 'woocommerce' ); ?></button>
@ -198,6 +207,10 @@ if ( ! defined( 'ABSPATH' ) ) {
$methods_placed_in_order = array_merge( $methods_placed_in_order, array_values( $methods ) );
foreach ( $methods_placed_in_order as $method ) {
if ( CartCheckoutUtils::is_checkout_block_default() && ! ShippingController::is_legacy_local_pickup_active() && 'local_pickup' === $method->id ) {
continue;
}
if ( ! $method->supports( 'shipping-zones' ) ) {
continue;
}
@ -214,7 +227,36 @@ if ( ! defined( 'ABSPATH' ) ) {
echo '<div id=' . esc_attr( $method->id ) . '-description class="wc-shipping-zone-method-input-help-text"><span>' . wp_kses_post( wpautop( $method->get_method_description() ) ) . '</span></div>';
}
echo '</div>'
if ( CartCheckoutUtils::is_checkout_block_default() ) {
echo '<p class="wc-shipping-legacy-local-pickup-help-text-container">';
if ( ShippingController::is_legacy_local_pickup_active() ) {
printf(
wp_kses(
/* translators: %s: Local pickup settings page URL. */
__( 'Explore a new enhanced delivery method that allows you to easily offer one or more pickup locations to your customers in the <a href="%s">Local pickup settings page</a>.', 'woocommerce' ),
array( 'a' => array( 'href' => array() ) )
),
esc_url( admin_url( 'admin.php?page=wc-settings&tab=shipping&section=pickup_location' ) )
);
} else {
printf(
wp_kses(
/* translators: %s: Local pickup settings page URL. */
__( 'Local pickup: Set up pickup locations in the <a href="%s">Local pickup settings page</a>.', 'woocommerce' ),
array( 'a' => array( 'href' => array() ) )
),
esc_url( admin_url( 'admin.php?page=wc-settings&tab=shipping&section=pickup_location' ) )
);
}
echo '</p>';
}
echo '</div>';
?>
</fieldset>
</form>

View File

@ -159,7 +159,11 @@ class ShippingController {
if ( CartCheckoutUtils::is_checkout_block_default() && $this->local_pickup_enabled ) {
foreach ( $settings as $index => $setting ) {
if ( 'woocommerce_shipping_cost_requires_address' === $setting['id'] ) {
$settings[ $index ]['desc'] .= ' (' . __( 'Not available when using WooCommerce Blocks Local Pickup', 'woocommerce' ) . ')';
$settings[ $index ]['desc'] = sprintf(
/* translators: %s: URL to the documentation. */
__( 'Not available when using the <a href="%s">Local pickup options powered by the Checkout block</a>.', 'woocommerce' ),
'https://woo.com/document/woocommerce-blocks-local-pickup/'
);
$settings[ $index ]['disabled'] = true;
$settings[ $index ]['value'] = 'no';
break;
@ -488,4 +492,29 @@ class ShippingController {
return $served;
}
/**
* Check if legacy local pickup is activated in any of the shipping zones or in the Rest of the World zone.
*
* @since 8.8.0
*
* @return bool
*/
public static function is_legacy_local_pickup_active() {
$rest_of_the_world = \WC_Shipping_Zones::get_zone_by( 'zone_id', 0 );
$shipping_zones = \WC_Shipping_Zones::get_zones();
$rest_of_the_world_data = $rest_of_the_world->get_data();
$rest_of_the_world_data['shipping_methods'] = $rest_of_the_world->get_shipping_methods();
array_unshift( $shipping_zones, $rest_of_the_world_data );
foreach ( $shipping_zones as $zone ) {
foreach ( $zone['shipping_methods'] as $method ) {
if ( 'local_pickup' === $method->id && $method->is_enabled() ) {
return true;
}
}
}
return false;
}
}

View File

@ -15,12 +15,6 @@ class CartCheckoutUtils {
if ( wc_current_theme_is_fse_theme() ) {
// Ignore the pages and check the templates.
$templates_from_db = BlockTemplateUtils::get_block_templates_from_db( array( 'cart' ), 'wp_template' );
// If there is no template file, we're using default which does use the block.
if ( empty( $templates_from_db ) ) {
return true;
}
foreach ( $templates_from_db as $template ) {
if ( has_block( 'woocommerce/cart', $template->content ) ) {
return true;
@ -40,12 +34,6 @@ class CartCheckoutUtils {
if ( wc_current_theme_is_fse_theme() ) {
// Ignore the pages and check the templates.
$templates_from_db = BlockTemplateUtils::get_block_templates_from_db( array( 'checkout' ), 'wp_template' );
// If there is no template file, we're using default which does use the block.
if ( empty( $templates_from_db ) ) {
return true;
}
foreach ( $templates_from_db as $template ) {
if ( has_block( 'woocommerce/checkout', $template->content ) ) {
return true;