Skip to content

Commit

Permalink
Fix logic to retrieve initial shipping rates for ECE on shortcode car…
Browse files Browse the repository at this point in the history
…t and checkout pages (#9322)
  • Loading branch information
rafaelzaleski authored Aug 26, 2024
1 parent 1a1616e commit 244b7c9
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
4 changes: 4 additions & 0 deletions changelog/fix-ece-shortcode-get-shipping-rates
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

Fix shipping rates retrieval method for shortcode cart/checkout.
7 changes: 2 additions & 5 deletions client/express-checkout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,7 @@ jQuery( ( $ ) => {
}

return options.displayItems
.filter(
( i ) =>
i.label === __( 'Shipping', 'woocommerce-payments' )
)
.filter( ( i ) => i.key === 'total_shipping' )
.map( ( i ) => ( {
id: `rate-${ i.label }`,
amount: i.amount,
Expand All @@ -228,7 +225,7 @@ jQuery( ( $ ) => {
// Relying on what's provided in the cart response seems safest since it should always include a valid shipping
// rate if one is required and available.
// If no shipping rate is found we can't render the button so we just exit.
if ( options.requestShipping && ! shippingRates ) {
if ( options.requestShipping && ! shippingRates.length ) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public function build_display_items( $itemized_display_items = false ) {
if ( WC()->cart->needs_shipping() ) {
$shipping_tax = $this->cart_prices_include_tax() ? WC()->cart->shipping_tax_total : 0;
$items[] = [
'key' => 'total_shipping',
'label' => esc_html( __( 'Shipping', 'woocommerce-payments' ) ),
'amount' => WC_Payments_Utils::prepare_amount( $shipping + $shipping_tax, $currency ),
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ public function test_get_shipping_options_returns_chosen_option() {
[
'label' => 'Shipping',
'amount' => $flat_rate['amount'],
'key' => 'total_shipping',
],
];

Expand Down

0 comments on commit 244b7c9

Please sign in to comment.