Add CartScriptParams returning currency and country code.

This commit is contained in:
Pedro Silva 2023-08-30 08:37:09 +01:00
parent 93afeeba68
commit 33ea69d7c8
No known key found for this signature in database
GPG key ID: E2EE20C0669D24B3
2 changed files with 14 additions and 0 deletions

View file

@ -11,6 +11,7 @@ namespace WooCommerce\PayPalCommerce\Button\Endpoint;
use Psr\Log\LoggerInterface;
use Throwable;
use WooCommerce\PayPalCommerce\ApiClient\Entity\Money;
use WooCommerce\PayPalCommerce\Button\Assets\SmartButton;
/**
@ -71,12 +72,24 @@ class CartScriptParamsEndpoint implements EndpointInterface {
$script_data = $this->smart_button->script_data();
$total = (float) WC()->cart->get_total( 'numeric' );
// Shop settings.
$base_location = wc_get_base_location();
$shop_country_code = $base_location['country'];
$currency_code = 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' ),
'total' => $total,
'total_str' => ( new Money( $total, $currency_code ) )->value_str(),
'currency_code' => $currency_code,
'country_code' => $shop_country_code,
)
);

View file

@ -101,6 +101,7 @@ class SimulateCartEndpoint extends AbstractCartEndpoint {
$button_enabled = $button_enabled && ! $this->smart_button->is_button_disabled( 'product', $context_data );
}
// Shop settings.
$base_location = wc_get_base_location();
$shop_country_code = $base_location['country'];
$currency_code = get_woocommerce_currency();