Testing shipping fields updating ApplePay addresses on checkout page

This commit is contained in:
Pedro Silva 2023-11-06 10:15:56 +00:00
parent e52acf3c60
commit d49eb60358
No known key found for this signature in database
GPG key ID: E2EE20C0669D24B3
4 changed files with 98 additions and 21 deletions

View file

@ -79,17 +79,49 @@ class CartScriptParamsEndpoint implements EndpointInterface {
$shop_country_code = $base_location['country'] ?? '';
$currency_code = get_woocommerce_currency();
$calculated_packages = WC()->shipping->calculate_shipping(
WC()->cart->get_shipping_packages()
);
$shipping_packages = array();
foreach ( $calculated_packages[0]['rates'] as $rate ) {
$rate_cost = $rate->get_cost();
/**
* The shipping rate.
*
* @var \WC_Shipping_Rate $rate
*/
$shipping_packages[] = array(
'id' => $rate->get_id(),
'label' => $rate->get_label(),
'cost' => (float) $rate_cost,
'cost_str' => ( new Money( (float) $rate_cost, $currency_code ) )->value_str(),
'description' => html_entity_decode(
wp_strip_all_tags(
wc_price( (float) $rate->get_cost(), array( 'currency' => get_woocommerce_currency() ) )
)
),
);
}
wp_send_json_success(
array(
'url_params' => $script_data['url_params'],
'button' => $script_data['button'],
'messages' => $script_data['messages'],
'amount' => WC()->cart->get_total( 'raw' ),
'url_params' => $script_data['url_params'],
'button' => $script_data['button'],
'messages' => $script_data['messages'],
'amount' => WC()->cart->get_total( 'raw' ),
'total' => $total,
'total_str' => ( new Money( $total, $currency_code ) )->value_str(),
'currency_code' => $currency_code,
'country_code' => $shop_country_code,
'total' => $total,
'total_str' => ( new Money( $total, $currency_code ) )->value_str(),
'currency_code' => $currency_code,
'country_code' => $shop_country_code,
'chosen_shipping_methods' => WC()->session->get( 'chosen_shipping_methods' ),
'shipping_packages' => $shipping_packages
)
);