mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 18:16:38 +08:00
Add CartScriptParams returning currency and country code.
This commit is contained in:
parent
93afeeba68
commit
33ea69d7c8
2 changed files with 14 additions and 0 deletions
|
@ -11,6 +11,7 @@ namespace WooCommerce\PayPalCommerce\Button\Endpoint;
|
||||||
|
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
use WooCommerce\PayPalCommerce\ApiClient\Entity\Money;
|
||||||
use WooCommerce\PayPalCommerce\Button\Assets\SmartButton;
|
use WooCommerce\PayPalCommerce\Button\Assets\SmartButton;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -71,12 +72,24 @@ class CartScriptParamsEndpoint implements EndpointInterface {
|
||||||
|
|
||||||
$script_data = $this->smart_button->script_data();
|
$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(
|
wp_send_json_success(
|
||||||
array(
|
array(
|
||||||
'url_params' => $script_data['url_params'],
|
'url_params' => $script_data['url_params'],
|
||||||
'button' => $script_data['button'],
|
'button' => $script_data['button'],
|
||||||
'messages' => $script_data['messages'],
|
'messages' => $script_data['messages'],
|
||||||
'amount' => WC()->cart->get_total( 'raw' ),
|
'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,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -101,6 +101,7 @@ class SimulateCartEndpoint extends AbstractCartEndpoint {
|
||||||
$button_enabled = $button_enabled && ! $this->smart_button->is_button_disabled( 'product', $context_data );
|
$button_enabled = $button_enabled && ! $this->smart_button->is_button_disabled( 'product', $context_data );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Shop settings.
|
||||||
$base_location = wc_get_base_location();
|
$base_location = wc_get_base_location();
|
||||||
$shop_country_code = $base_location['country'];
|
$shop_country_code = $base_location['country'];
|
||||||
$currency_code = get_woocommerce_currency();
|
$currency_code = get_woocommerce_currency();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue