Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Always show the Enable the shipping calculator on the cart page opt…
Browse files Browse the repository at this point in the history
…ion in WC Admin (#11421)

* Always show `Enable the shipping calculator ...`

Always show the `Enable the shipping calculator on the cart page` option
no matter of what is used for the cart page.

* Update remove_shipping_settings docblock to accurately describe its purpose.

---------

Co-authored-by: Mike Jolley <[email protected]>
  • Loading branch information
2 people authored and danieldudzic committed Oct 24, 2023
1 parent 1d443f6 commit 975cb5b
Showing 1 changed file with 2 additions and 42 deletions.
44 changes: 2 additions & 42 deletions src/Shipping/ShippingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,52 +171,12 @@ public function show_local_pickup_details( $return, $order ) {
}

/**
* If the Checkout block Remove shipping settings from WC Core's admin panels that are now block settings.
* When using the cart and checkout blocks this method is used to adjust core shipping settings via a filter hook.
*
* @param array $settings The default WC shipping settings.
* @return array|mixed The filtered settings with relevant items removed.
* @return array|mixed The filtered settings.
*/
public function remove_shipping_settings( $settings ) {

// Do not add the shipping calculator setting if the Cart block is not used on the WC cart page.
if ( CartCheckoutUtils::is_cart_block_default() ) {

// Ensure the 'Calculations' title is added to the `woocommerce_shipping_cost_requires_address` options
// group, since it is attached to the `woocommerce_enable_shipping_calc` option that gets removed if the
// Cart block is in use.
$calculations_title = '';

// Get Calculations title so we can add it to 'Hide shipping costs until an address is entered' option.
foreach ( $settings as $setting ) {
if ( 'woocommerce_enable_shipping_calc' === $setting['id'] ) {
$calculations_title = $setting['title'];
break;
}
}

// Add Calculations title to 'Hide shipping costs until an address is entered' option.
foreach ( $settings as $index => $setting ) {
if ( 'woocommerce_shipping_cost_requires_address' === $setting['id'] ) {
$settings[ $index ]['title'] = $calculations_title;
$settings[ $index ]['checkboxgroup'] = 'start';
break;
}
}

$settings = array_filter(
$settings,
function( $setting ) {
return ! in_array(
$setting['id'],
array(
'woocommerce_enable_shipping_calc',
),
true
);
}
);
}

if ( CartCheckoutUtils::is_checkout_block_default() && $this->local_pickup_enabled ) {
foreach ( $settings as $index => $setting ) {
if ( 'woocommerce_shipping_cost_requires_address' === $setting['id'] ) {
Expand Down

0 comments on commit 975cb5b

Please sign in to comment.