| Server IP : 38.190.208.107 / Your IP : 216.73.217.46 Web Server : nginx/1.28.1 System : Linux ht2026040333114 6.1.0-10-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.37-1 (2023-07-03) x86_64 User : root ( 0) PHP Version : 8.2.28 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv,eval,assert,passthru,system,exec,shell_exec,popen,proc_open MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /www/wwwroot/wp.5/wp-content/plugins/woocommerce-payments/includes/multi-currency/ |
Upload File : |
<?php
/**
* WooCommerce Payments Multi-Currency User Settings
*
* @package WooCommerce\Payments
*/
namespace WCPay\MultiCurrency;
defined( 'ABSPATH' ) || exit;
/**
* Class that add Multi-Currency settings to user my account page.
*/
class UserSettings {
/**
* Multi-Currency instance.
*
* @var MultiCurrency
*/
protected $multi_currency;
/**
* Constructor.
*
* @param MultiCurrency $multi_currency The MultiCurrency instance.
*/
public function __construct( MultiCurrency $multi_currency ) {
$this->multi_currency = $multi_currency;
}
/**
* Initializes this class' WP hooks.
*
* @return void
*/
public function init_hooks() {
// Only show currency selector if more than one currency is enabled.
if ( 1 < count( $this->multi_currency->get_enabled_currencies() ) ) {
add_action( 'woocommerce_edit_account_form', [ $this, 'add_presentment_currency_switch' ] );
add_action( 'woocommerce_save_account_details', [ $this, 'save_presentment_currency' ] );
}
}
/**
* Add a select to allow user choose default currency in `my account > account details`.
*
* @return void
*/
public function add_presentment_currency_switch() {
?>
<p class="woocommerce-form-row woocommerce-form-row--first form-row form-row-first">
<label for="wcpay_selected_currency"><?php esc_html_e( 'Default currency', 'woocommerce-payments' ); ?></label>
<select
name="wcpay_selected_currency"
id="wcpay_selected_currency"
>
<?php
foreach ( $this->multi_currency->get_enabled_currencies() as $currency ) {
$code = $currency->get_code();
$symbol = $currency->get_symbol();
$selected = $this->multi_currency->get_selected_currency()->code === $code ? ' selected' : '';
echo "<option value=\"$code\"$selected>$symbol $code</option>"; // phpcs:ignore WordPress.Security.EscapeOutput
}
?>
</select>
<span><em><?php esc_html_e( 'Select your preferred currency for shopping and payments.', 'woocommerce-payments' ); ?></em></span>
</p>
<div class="clear"></div>
<?php
}
/**
* Hook into save account details to capture the new value `wcpay_selected_currency` and persist it.
*
* @return void
*/
public function save_presentment_currency() {
if ( isset( $_POST['wcpay_selected_currency'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
$currency_code = wc_clean( wp_unslash( $_POST['wcpay_selected_currency'] ) ); // phpcs:ignore WordPress.Security.NonceVerification
$this->multi_currency->update_selected_currency( $currency_code );
}
}
}