| Server IP : 185.143.234.238 / Your IP : 185.215.232.195 Web Server : LiteSpeed System : Linux saman.shetabanhost.com 4.18.0-553.121.1.lve.el8.x86_64 #1 SMP Thu Apr 30 16:40:41 UTC 2026 x86_64 User : behrakir ( 1361) PHP Version : 8.1.34 Disable Function : symlink,shell_exec,show_source,exec,popen,system,passthru,proc_open,proc_close,pcntl_exec,mail MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/behrakir/khanomam.com/wp-content/plugins/woo-wallet/includes/ |
Upload File : |
<?php
/**
* Woo Wallet settings
*
* @author Subrata Mal
* @package StandaloneTech
*/
if ( ! class_exists( 'Woo_Wallet_Settings' ) ) :
/**
* Plugin settings page class
*/
class Woo_Wallet_Settings {
/**
* Settings api object
*
* @var Woo_Wallet_Settings_API
*/
private $settings_api;
/**
* Class constructor
*
* @param Woo_Wallet_Settings_API $settings_api settings_api.
*/
public function __construct( $settings_api ) {
$this->settings_api = $settings_api;
add_action( 'admin_init', array( $this, 'plugin_settings_page_init' ) );
add_action( 'admin_menu', array( $this, 'admin_menu' ), 60 );
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
}
/**
* WC wallet menu
*/
public function admin_menu() {
add_submenu_page( 'woo-wallet', __( 'Settings', 'woo-wallet' ), __( 'Settings', 'woo-wallet' ), get_wallet_user_capability(), 'woo-wallet-settings', array( $this, 'plugin_page' ) );
}
/**
* Admin init
*/
public function plugin_settings_page_init() {
// set the settings.
$this->settings_api->set_sections( $this->get_settings_sections() );
foreach ( $this->get_settings_sections() as $section ) {
if ( method_exists( $this, "update_option_{$section['id']}_callback" ) ) {
add_action( "update_option_{$section['id']}", array( $this, "update_option_{$section['id']}_callback" ), 10, 3 );
}
}
$this->settings_api->set_fields( $this->get_settings_fields() );
// initialize settings.
$this->settings_api->admin_init();
}
/**
* Enqueue scripts and styles
*/
public function admin_enqueue_scripts() {
$screen = get_current_screen();
$screen_id = $screen ? $screen->id : '';
$woo_wallet_settings_screen_id = sanitize_title( __( 'TeraWallet', 'woo-wallet' ) );
if ( ! in_array( $screen_id, array( "{$woo_wallet_settings_screen_id}_page_woo-wallet-settings" ), true ) ) {
return;
}
// React settings bundle (generated by wcBuildConfig via @wordpress/scripts).
$asset_file = WOO_WALLET_ABSPATH . 'build/admin/settings/index.asset.php';
$asset = file_exists( $asset_file ) ? require $asset_file : array(
'dependencies' => array(),
'version' => WOO_WALLET_PLUGIN_VERSION,
);
wp_enqueue_style(
'woo-wallet-admin-settings',
woo_wallet()->plugin_url() . '/build/admin/settings/index.css',
array( 'wp-components' ),
$asset['version']
);
wp_enqueue_script(
'woo-wallet-admin-settings',
woo_wallet()->plugin_url() . '/build/admin/settings/index.js',
$asset['dependencies'],
$asset['version'],
true
);
// wp.media() needed for the attachment/image field type.
wp_enqueue_media();
wp_localize_script(
'woo-wallet-admin-settings',
'wooWalletSettingsData',
array(
'restUrl' => esc_url_raw( rest_url( 'terawallet/v1/settings' ) ),
'restNonce' => wp_create_nonce( 'wp_rest' ),
'pluginUrl' => woo_wallet()->plugin_url(),
'version' => WOO_WALLET_PLUGIN_VERSION,
)
);
}
/**
* Setting sections
*
* @return array
*/
public function get_settings_sections() {
$sections = array(
array(
'id' => '_wallet_settings_general',
'title' => __( 'General Options', 'woo-wallet' ),
'icon' => 'dashicons-admin-generic',
),
array(
'id' => '_wallet_settings_credit',
'title' => __( 'Credit Options', 'woo-wallet' ),
'icon' => 'dashicons-money-alt',
),
array(
'id' => '_wallet_settings_actions',
'title' => __( 'Actions', 'woo-wallet' ),
'description' => __( 'Automated wallet events', 'woo-wallet' ),
'icon' => 'actions',
),
);
return apply_filters( 'woo_wallet_settings_sections', $sections );
}
/**
* Returns all the settings fields
*
* @return array settings fields
*/
public function get_settings_fields() {
$topup_show_if = array(
'field' => 'is_enable_wallet_topup',
'equals' => 'on',
);
$partial_show_if = array(
'field' => 'is_enable_partial_payment',
'equals' => 'on',
);
$transfer_show_if = array(
'field' => 'is_enable_wallet_transfer',
'equals' => 'on',
);
$charge_show_if = array(
'field' => 'is_enable_gateway_charge',
'equals' => 'on',
);
// Build topup fields, threading the group + show_if onto each.
$topup_fields = array(
array(
'name' => 'is_enable_wallet_topup',
'label' => __( 'Enable Wallet Topup', 'woo-wallet' ),
'desc' => __( 'Allow users to add funds to their wallet balance', 'woo-wallet' ),
'type' => 'checkbox',
'default' => 'on',
'group' => 'wallet_topup',
'group_title' => __( 'Wallet Topup', 'woo-wallet' ),
'group_description' => __( 'Control how users add funds to their wallet', 'woo-wallet' ),
),
array(
'name' => 'product_title',
'label' => __( 'Rechargeable Product Title', 'woo-wallet' ),
'desc' => __( 'This title appears on the wallet topup product page', 'woo-wallet' ),
'type' => 'text',
'default' => $this->get_rechargeable_product_title(),
'group' => 'wallet_topup',
'show_if' => $topup_show_if,
),
array(
'name' => 'product_image',
'label' => __( 'Product Image', 'woo-wallet' ),
'desc' => __( 'Upload a representative image for the wallet topup product', 'woo-wallet' ),
'type' => 'attachment',
'options' => array(
'button_label' => __( 'Set product image', 'woo-wallet' ),
'uploader_title' => __( 'Product image', 'woo-wallet' ),
'uploader_button_text' => __( 'Set product image', 'woo-wallet' ),
),
'group' => 'wallet_topup',
'show_if' => $topup_show_if,
),
);
foreach ( $this->get_wc_tax_options() as $tax_field ) {
$tax_field['group'] = 'wallet_topup';
$tax_field['show_if'] = $topup_show_if;
$topup_fields[] = $tax_field;
}
$topup_fields = array_merge(
$topup_fields,
array(
array(
'name' => 'min_topup_amount',
'label' => __( 'Minimum Topup Amount', 'woo-wallet' ),
'desc' => __( 'Leave blank for no minimum', 'woo-wallet' ),
'type' => 'number',
'prefix' => get_woocommerce_currency_symbol( get_option( 'woocommerce_currency' ) ),
'step' => '0.01',
'group' => 'wallet_topup',
'show_if' => $topup_show_if,
'half' => true,
),
array(
'name' => 'max_topup_amount',
'label' => __( 'Maximum Topup Amount', 'woo-wallet' ),
'desc' => __( 'Leave blank for no maximum', 'woo-wallet' ),
'type' => 'number',
'prefix' => get_woocommerce_currency_symbol( get_option( 'woocommerce_currency' ) ),
'step' => '0.01',
'group' => 'wallet_topup',
'show_if' => $topup_show_if,
'half' => true,
),
array(
'name' => 'allowed_payment_gateways',
'label' => __( 'Allowed Payment Gateways', 'woo-wallet' ),
'desc' => __( 'Select one or more gateways to enable for wallet funding', 'woo-wallet' ),
'type' => 'select',
'options' => $this->get_wc_payment_allowed_gateways(),
'default' => array_keys( $this->get_wc_payment_allowed_gateways() ),
'size' => 'regular-text wc-enhanced-select',
'multiple' => true,
'group' => 'wallet_topup',
'show_if' => $topup_show_if,
),
array(
'name' => 'is_enable_gateway_charge',
'label' => __( 'Apply Gateway Charge', 'woo-wallet' ),
'desc' => __( 'Pass transaction fees to the customer when they add wallet balance', 'woo-wallet' ),
'type' => 'checkbox',
'group' => 'wallet_topup',
'show_if' => $topup_show_if,
),
array(
'name' => 'gateway_charge_type',
'label' => __( 'Charge Type', 'woo-wallet' ),
'desc' => __( 'Choose how the gateway fee is calculated', 'woo-wallet' ),
'type' => 'select',
'options' => array(
'percent' => __( 'Percentage (%)', 'woo-wallet' ),
'fixed' => __( 'Fixed', 'woo-wallet' ),
),
'size' => 'regular-text wc-enhanced-select',
'group' => 'wallet_topup',
'show_if' => array( $topup_show_if, $charge_show_if ),
),
)
);
foreach ( $this->get_wc_payment_gateways() as $gw_field ) {
$gw_field['group'] = 'wallet_topup';
$gw_field['show_if'] = array( $topup_show_if, $charge_show_if );
$topup_fields[] = $gw_field;
}
$partial_fields = array(
array(
'name' => 'is_enable_partial_payment',
'label' => __( 'Enable Partial Payment', 'woo-wallet' ),
'desc' => __( 'Let users pay part of an order with their wallet balance', 'woo-wallet' ),
'type' => 'checkbox',
'default' => 'on',
'group' => 'partial_payment',
'group_title' => __( 'Partial Payment', 'woo-wallet' ),
'group_description' => __( 'Use wallet balance alongside other payment methods', 'woo-wallet' ),
),
array(
'name' => 'is_auto_deduct_for_partial_payment',
'label' => __( 'Auto deduct wallet balance', 'woo-wallet' ),
'desc' => __( 'When the order total exceeds the wallet balance, deduct the balance first and charge the remainder to the selected payment method', 'woo-wallet' ),
'type' => 'checkbox',
'group' => 'partial_payment',
'show_if' => $partial_show_if,
),
array(
'name' => 'partial_payment_tax_treatment',
'label' => __( 'Tax treatment', 'woo-wallet' ),
'desc' => __( 'How the wallet interacts with order tax. "Wallet pays goods only" charges the tax on the order (correct when top-ups are not taxed). "Wallet pays the whole order including tax" lets the wallet cover the tax line — use this ONLY when top-ups are set Taxable, otherwise tax is under-collected. Confirm with your accountant.', 'woo-wallet' ),
'type' => 'select',
'options' => array(
'payment' => __( 'Wallet pays goods only; tax charged on order (recommended)', 'woo-wallet' ),
'tax_inclusive_wallet' => __( 'Wallet pays the whole order including tax (top-ups taxed at load)', 'woo-wallet' ),
),
'default' => 'payment',
'size' => 'regular-text wc-enhanced-select',
'group' => 'partial_payment',
'show_if' => $partial_show_if,
),
array(
'name' => 'partial_payment_debit_on',
'label' => __( 'Deduct wallet balance', 'woo-wallet' ),
'desc' => __( 'When to deduct the wallet amount. "At order placement" reserves the balance immediately (default). "When payment completes" deducts only once the order reaches a paid status — if the balance was spent meanwhile the order is held for review.', 'woo-wallet' ),
'type' => 'select',
'options' => array(
'order_created' => __( 'At order placement', 'woo-wallet' ),
'payment_complete' => __( 'When payment completes', 'woo-wallet' ),
),
'default' => 'order_created',
'size' => 'regular-text wc-enhanced-select',
'group' => 'partial_payment',
'show_if' => $partial_show_if,
),
array(
'name' => 'partial_payment_refund_on_partial_refund',
'label' => __( 'Refund wallet on partial refunds', 'woo-wallet' ),
'desc' => __( 'When you issue a partial refund on an order, return the wallet-paid portion proportionally to the customer wallet. Full cancellations always refund the wallet.', 'woo-wallet' ),
'type' => 'checkbox',
'default' => 'on',
'group' => 'partial_payment',
'show_if' => $partial_show_if,
),
);
$transfer_fields = array(
array(
'name' => 'is_enable_wallet_transfer',
'label' => __( 'Enable Wallet Transfer', 'woo-wallet' ),
'desc' => __( 'Allow users to send wallet balance to other registered customers', 'woo-wallet' ),
'type' => 'checkbox',
'default' => 'on',
'group' => 'wallet_transfer',
'group_title' => __( 'Wallet Transfer', 'woo-wallet' ),
'group_description' => __( 'Peer-to-peer wallet transfer settings', 'woo-wallet' ),
),
array(
'name' => 'min_transfer_amount',
'label' => __( 'Minimum Transfer Amount', 'woo-wallet' ),
'desc' => __( 'Users cannot transfer less than this amount', 'woo-wallet' ),
'type' => 'number',
'prefix' => get_woocommerce_currency_symbol( get_option( 'woocommerce_currency' ) ),
'step' => '0.01',
'group' => 'wallet_transfer',
'show_if' => $transfer_show_if,
'half' => true,
),
array(
'name' => 'max_transfer_amount',
'label' => __( 'Maximum Transfer Amount', 'woo-wallet' ),
'desc' => __( 'Users cannot transfer more than this amount', 'woo-wallet' ),
'type' => 'number',
'prefix' => get_woocommerce_currency_symbol( get_option( 'woocommerce_currency' ) ),
'step' => '0.01',
'group' => 'wallet_transfer',
'show_if' => $transfer_show_if,
'half' => true,
),
array(
'name' => 'transfer_charge_type',
'label' => __( 'Transfer Charge Type', 'woo-wallet' ),
'desc' => __( 'Choose how the transfer fee is calculated', 'woo-wallet' ),
'type' => 'select',
'options' => array(
'percent' => __( 'Percentage (%)', 'woo-wallet' ),
'fixed' => __( 'Fixed', 'woo-wallet' ),
),
'size' => 'regular-text wc-enhanced-select',
'group' => 'wallet_transfer',
'show_if' => $transfer_show_if,
'half' => true,
),
array(
'name' => 'transfer_charge_amount',
'label' => __( 'Transfer Charge Amount', 'woo-wallet' ),
'desc' => __( 'Fee charged to the sender for each transfer', 'woo-wallet' ),
'type' => 'number',
'step' => '0.01',
'group' => 'wallet_transfer',
'show_if' => $transfer_show_if,
'half' => true,
),
);
$cashbak_show_if = array(
'field' => 'is_enable_cashback_reward_program',
'equals' => 'on',
);
// Per-currency ledger mode is gated by a filter through PR2 — when the
// flag flips on, this field appears under General Options and admins can
// switch the storage semantics. Surfaced as an empty array otherwise so
// the array_merge below stays uniform.
$currency_handling_fields = array();
if ( apply_filters( 'woo_wallet_enable_per_currency_mode', false ) ) {
$currency_handling_fields[] = array(
'name' => 'wallet_currency_mode',
'label' => __( 'Wallet Currency Mode', 'woo-wallet' ),
'desc' => __( 'How wallet transactions are stored across currencies. "Single base currency" normalizes every credit/debit to the shop base on write — safest default. "Per-currency sub-balances" stores each transaction in its own currency so customers see balances per currency.', 'woo-wallet' ),
'type' => 'select',
'options' => array(
'single_base' => __( 'Single base currency (recommended)', 'woo-wallet' ),
'per_currency' => __( 'Per-currency sub-balances', 'woo-wallet' ),
),
'default' => 'single_base',
'size' => 'regular-text',
'group' => 'currency_handling',
'group_title' => __( 'Currency Handling', 'woo-wallet' ),
'group_description' => __( 'Multi-currency storage and display behaviour', 'woo-wallet' ),
);
}
$settings_fields = array(
'_wallet_settings_actions' => $this->get_actions_settings_fields(),
'_wallet_settings_general' => array_merge(
$topup_fields,
$partial_fields,
$transfer_fields,
$currency_handling_fields,
$this->wp_menu_locations()
),
'_wallet_settings_credit' => array_merge(
array(
array(
'name' => 'is_enable_cashback_reward_program',
'label' => __( 'Enable Cashback Rewards', 'woo-wallet' ),
'desc' => __( 'Customers earn wallet credit on qualifying orders', 'woo-wallet' ),
'type' => 'checkbox',
'group' => 'wallet_cashback',
'group_title' => __( 'Cashback Rewards', 'woo-wallet' ),
'group_description' => __( 'Reward customers with wallet credits on purchases', 'woo-wallet' ),
),
array(
'name' => 'process_cashback_status',
'label' => __( 'Process cashback', 'woo-wallet' ),
'desc' => __( 'Select order status to process cashback', 'woo-wallet' ),
'type' => 'select',
'group' => 'wallet_cashback',
'options' => apply_filters(
'woo_wallet_process_cashback_status',
wc_get_order_statuses()
),
'default' => array( 'processing', 'completed' ),
'size' => 'regular-text wc-enhanced-select',
'multiple' => true,
'show_if' => $cashbak_show_if,
),
array(
'name' => 'exclude_role',
'label' => __( 'Exclude user role', 'woo-wallet' ),
'desc' => __( 'This option lets you specify which user role you want to exclude from the cashback program.', 'woo-wallet' ),
'type' => 'select',
'group' => 'wallet_cashback',
'options' => $this->get_editable_role_options(),
'default' => array(),
'size' => 'regular-text wc-enhanced-select',
'multiple' => true,
'show_if' => $cashbak_show_if,
),
array(
'name' => 'cashback_rule',
'label' => __( 'Cashback Rule', 'woo-wallet' ),
'desc' => __( 'Select Cashback Rule cart or product wise', 'woo-wallet' ),
'type' => 'select',
'group' => 'wallet_cashback',
'options' => apply_filters(
'woo_wallet_cashback_rules',
array(
'cart' => __( 'Cart wise', 'woo-wallet' ),
'product' => __( 'Product wise', 'woo-wallet' ),
'product_cat' => __(
'Product category wise',
'woo-wallet'
),
)
),
'size' => 'regular-text wc-enhanced-select',
'show_if' => $cashbak_show_if,
),
array(
'name' => 'cashback_type',
'label' => __( 'Cashback type', 'woo-wallet' ),
'desc' => __( 'Select cashback type percentage or fixed', 'woo-wallet' ),
'type' => 'select',
'group' => 'wallet_cashback',
'options' => array(
'percent' => __( 'Percentage', 'woo-wallet' ),
'fixed' => __( 'Fixed', 'woo-wallet' ),
),
'size' => 'regular-text wc-enhanced-select',
'show_if' => $cashbak_show_if,
'half' => true,
),
array(
'name' => 'cashback_amount',
'label' => __( 'Cashback Amount', 'woo-wallet' ),
'desc' => __( 'Enter cashback amount', 'woo-wallet' ),
'type' => 'number',
'group' => 'wallet_cashback',
'step' => '0.01',
'show_if' => $cashbak_show_if,
'half' => true,
),
array(
'name' => 'min_cart_amount',
'label' => __( 'Minimum Cart Amount', 'woo-wallet' ),
'desc' => __( 'Enter applicable minimum cart amount for cashback', 'woo-wallet' ),
'type' => 'number',
'prefix' => get_woocommerce_currency_symbol( get_option( 'woocommerce_currency' ) ),
'group' => 'wallet_cashback',
'step' => '0.01',
'show_if' => array(
$cashbak_show_if,
array(
'field' => 'cashback_rule',
'equals' => 'cart',
),
),
),
array(
'name' => 'max_cashback_amount',
'label' => __( 'Maximum Cashback Amount', 'woo-wallet' ),
'desc' => __( 'Enter maximum cashback amount', 'woo-wallet' ),
'type' => 'number',
'prefix' => get_woocommerce_currency_symbol( get_option( 'woocommerce_currency' ) ),
'group' => 'wallet_cashback',
'step' => '0.01',
'show_if' => $cashbak_show_if,
),
array(
'name' => 'allow_min_cashback',
'label' => __( 'Allow Minimum cashback', 'woo-wallet' ),
'desc' => __( 'If checked minimum cashback amount will be applied on product category cashback calculation.', 'woo-wallet' ),
'type' => 'checkbox',
'group' => 'wallet_cashback',
'default' => 'on',
'show_if' => array(
$cashbak_show_if,
array(
'field' => 'cashback_rule',
'equals' => 'product_cat',
),
),
),
array(
'name' => 'max_cashback_scope',
'label' => __( 'Maximum Cashback Cap Scope', 'woo-wallet' ),
'desc' => __( 'Per order: the global maximum is applied once to the cart/order total. Per item: the maximum is applied to each line item individually (legacy behaviour).', 'woo-wallet' ),
'type' => 'select',
'group' => 'wallet_cashback',
'default' => 'per_order',
'options' => array(
'per_order' => __( 'Per order (recommended)', 'woo-wallet' ),
'per_item' => __( 'Per item (legacy)', 'woo-wallet' ),
),
'size' => 'regular-text wc-enhanced-select',
'show_if' => $cashbak_show_if,
),
array(
'name' => 'cashback_clawback_on_refund',
'label' => __( 'Refund Clawback', 'woo-wallet' ),
'desc' => __( 'Claw back cashback prorated against the refunded fraction when an order is refunded. Off by default for upgrade safety.', 'woo-wallet' ),
'type' => 'checkbox',
'group' => 'wallet_cashback',
'default' => 'no',
'show_if' => $cashbak_show_if,
),
array(
'name' => 'cashback_clawback_allow_negative',
'label' => __( 'Allow Negative Clawback', 'woo-wallet' ),
'desc' => __( 'Allow the cashback reversal to drive the wallet negative when the customer has already spent the credit. Off by default (partial-debit policy applies instead).', 'woo-wallet' ),
'type' => 'checkbox',
'group' => 'wallet_cashback',
'default' => 'no',
'show_if' => $cashbak_show_if,
),
),
),
);
$settings_fields = apply_filters( 'woo_wallet_settings_filds', $settings_fields );
// Corrected-spelling alias — new plugins should use this name.
return apply_filters( 'woo_wallet_settings_fields', $settings_fields );
}
/**
* Build flattened action fields for the unified `_wallet_settings_actions` tab.
*
* Each WooWalletAction's form_fields are reshaped to the schema dialect used
* by the React Panel (label/desc/group) and prefixed with `{action_id}__` so
* every action's fields live in a single option row alongside the standard
* sections. The first field of each action carries `group_title`,
* `group_description`, `group_type=action`, and `group_enabled_field` so the
* frontend can render it as a collapsible action card with a master toggle.
*
* @return array
*/
public function get_actions_settings_fields() {
$fields = array();
if ( ! class_exists( 'WOO_Wallet_Actions' ) ) {
return $fields;
}
$currency_symbol = html_entity_decode( get_woocommerce_currency_symbol( get_option( 'woocommerce_currency' ) ), ENT_QUOTES | ENT_HTML5, 'UTF-8' );
foreach ( WOO_Wallet_Actions::instance()->actions as $action ) {
if ( empty( $action->form_fields ) ) {
$action->init_form_fields();
}
if ( empty( $action->form_fields ) ) {
continue;
}
$group_id = $action->id;
$is_first = true;
$enabled_key = $group_id . '__enabled';
foreach ( $action->form_fields as $key => $field ) {
$normalized = $this->normalize_action_form_field( $key, $field, $currency_symbol );
$normalized['name'] = $group_id . '__' . $normalized['name'];
$normalized['group'] = $group_id;
if ( isset( $normalized['show_if'] ) ) {
$normalized['show_if'] = $this->prefix_show_if( $normalized['show_if'], $group_id );
}
if ( $is_first ) {
$normalized['group_title'] = $action->get_action_title();
$normalized['group_description'] = $action->get_action_description();
$normalized['group_type'] = 'action';
$normalized['group_enabled_field'] = $enabled_key;
$is_first = false;
}
$fields[] = $normalized;
}
}
return $fields;
}
/**
* Reshape a single WC_Settings_API form_field into the React panel dialect.
*
* `title` becomes `label`, `description` becomes `desc`, `price` is split into
* `number` + `prefix`, and checkbox fields are marked `bool_format=yes_no` so
* the saver can preserve the legacy `'yes'/'no'` storage that the action
* subclasses' `is_enabled()` and per-field reads expect.
*
* @param string $key Original form field key.
* @param array $field WC_Settings_API field definition.
* @param string $currency_symbol Pre-decoded currency symbol for `price` fields.
* @return array
*/
private function normalize_action_form_field( $key, array $field, $currency_symbol ) {
$type = isset( $field['type'] ) ? $field['type'] : 'text';
// Section-title entries become renderable headings in the React panel.
if ( 'title' === $type ) {
return array(
'name' => isset( $field['id'] ) ? 'heading_' . $field['id'] : 'heading_' . $key,
'label' => isset( $field['title'] ) ? $field['title'] : '',
'desc' => isset( $field['desc'] ) ? $field['desc'] : '',
'type' => 'section_heading',
);
}
$result = array(
'name' => $key,
'label' => isset( $field['title'] ) ? $field['title'] : '',
'desc' => isset( $field['description'] ) ? $field['description'] : '',
'type' => $type,
'default' => isset( $field['default'] ) ? $field['default'] : '',
);
if ( 'price' === $type ) {
$result['type'] = 'number';
$result['prefix'] = $currency_symbol;
if ( ! isset( $field['step'] ) ) {
$result['step'] = '0.01';
}
}
if ( 'checkbox' === $type ) {
$result['bool_format'] = 'yes_no';
}
if ( isset( $field['options'] ) ) {
$result['options'] = $field['options'];
}
if ( isset( $field['placeholder'] ) ) {
$result['placeholder'] = $field['placeholder'];
}
if ( isset( $field['min'] ) ) {
$result['min'] = $field['min'];
}
if ( isset( $field['max'] ) ) {
$result['max'] = $field['max'];
}
if ( isset( $field['step'] ) ) {
$result['step'] = $field['step'];
}
if ( isset( $field['size'] ) ) {
$result['size'] = $field['size'];
}
if ( isset( $field['half'] ) ) {
$result['half'] = (bool) $field['half'];
}
if ( isset( $field['show_if'] ) ) {
$result['show_if'] = $field['show_if'];
}
return $result;
}
/**
* Re-prefix the `field` reference inside a `show_if` rule so it matches
* the flattened `{action_id}__{key}` names the React panel keys on.
* Accepts a single condition array or a list of condition arrays.
*
* @param array $show_if The raw show_if rule from the form field.
* @param string $group_id The owning action id.
* @return array
*/
private function prefix_show_if( $show_if, $group_id ) {
if ( ! is_array( $show_if ) ) {
return $show_if;
}
if ( isset( $show_if['field'] ) ) {
$show_if['field'] = $group_id . '__' . $show_if['field'];
return $show_if;
}
foreach ( $show_if as $index => $condition ) {
if ( is_array( $condition ) && isset( $condition['field'] ) ) {
$show_if[ $index ]['field'] = $group_id . '__' . $condition['field'];
}
}
return $show_if;
}
/**
* Convert the stored `_wallet_settings_actions` row into the shape the React
* UI expects: `'yes'`/`'no'` toggles flipped to `'on'`/`'off'` so the standard
* CheckboxField renders correctly. The saver performs the inverse mapping on
* write — see `TeraWallet_REST_Settings_Controller::save_section()`.
*
* @param array $stored Raw `_wallet_settings_actions` values.
* @return array
*/
public function prepare_actions_values_for_react( array $stored ) {
$prepared = $stored;
foreach ( $this->get_actions_settings_fields() as $field ) {
if ( empty( $field['bool_format'] ) || 'yes_no' !== $field['bool_format'] ) {
continue;
}
$name = $field['name'];
if ( ! array_key_exists( $name, $prepared ) ) {
$prepared[ $name ] = ( isset( $field['default'] ) && 'yes' === $field['default'] ) ? 'on' : 'off';
continue;
}
$prepared[ $name ] = ( 'yes' === $prepared[ $name ] ) ? 'on' : 'off';
}
return $prepared;
}
/**
* Fetch rechargeable product title
*
* @return string title
*/
public function get_rechargeable_product_title() {
$product_title = '';
$wallet_product = get_wallet_rechargeable_product();
if ( $wallet_product ) {
$product_title = $wallet_product->get_title();
}
return $product_title;
}
/**
* Display plugin settings page — mounts the React settings app.
*/
public function plugin_page() {
echo '<div class="wrap"><div id="woo-wallet-settings-root"></div></div>';
}
/**
* Chargeable payment gateways
*
* @param string $context context.
* @return array
*/
public function get_wc_payment_gateways( $context = 'field' ) {
$gateways = array();
foreach ( WC()->payment_gateways()->payment_gateways as $gateway ) {
if ( 'yes' === $gateway->enabled && 'wallet' !== $gateway->id ) {
$method_title = $gateway->get_title() ? $gateway->get_title() : __( '(no title)', 'woo-wallet' );
if ( 'field' === $context ) {
$gateways[] = array(
'name' => 'charge_amount_' . $gateway->id,
'label' => $method_title,
'desc' => __( 'Enter gateway charge amount for ', 'woo-wallet' ) . $method_title,
'type' => 'number',
'step' => '0.01',
);
} else {
$gateways[] = $gateway->id;
}
}
}
return $gateways;
}
/**
* Allowed payment gateways
*
* @param string $context context.
* @param string $prefix prefix.
* @return array
*/
public function get_wc_payment_allowed_gateways( $context = 'edit', $prefix = '' ) {
$gateways = array();
foreach ( WC()->payment_gateways()->payment_gateways as $gateway ) {
$method_title = $gateway->get_title() ? $gateway->get_title() : __( '(no title)', 'woo-wallet' );
if ( 'yes' === $gateway->enabled && 'wallet' !== $gateway->id ) {
if ( 'field' === $context ) {
$gateways[] = array(
'name' => $prefix . $gateway->id,
'label' => $method_title,
'desc' => __( 'Allow this gateway for recharge wallet', 'woo-wallet' ),
'type' => 'checkbox',
'default' => 'on',
);
} else {
$gateways[ $gateway->id ] = $method_title;
}
}
}
return $gateways;
}
/**
* Allowed payment gateways
*
* @param string $context context.
* @return array
*/
public function get_wc_tax_options( $context = 'field' ) {
$tax_options = array();
if ( wc_tax_enabled() ) {
$tax_options[] = array(
'name' => '_tax_status',
'label' => __( 'Rechargeable Product Tax status', 'woo-wallet' ),
'desc' => __( 'Define whether or not the rechargeable Product is taxable.', 'woo-wallet' ),
'type' => 'select',
'options' => array(
'taxable' => __( 'Taxable', 'woo-wallet' ),
'none' => _x( 'None', 'Tax status', 'woo-wallet' ),
),
'size' => 'regular-text wc-enhanced-select',
'half' => true,
);
$tax_options[] = array(
'name' => '_tax_class',
'label' => __( 'Rechargeable Product Tax class', 'woo-wallet' ),
'type' => 'select',
'options' => wc_get_product_tax_class_options(),
'desc' => __( 'Choose a tax class for rechargeable product.', 'woo-wallet' ),
'size' => 'regular-text wc-enhanced-select',
'half' => true,
);
}
return $tax_options;
}
/**
* Get all registered nav menu locations settings
*
* @return array
*/
public function wp_menu_locations() {
$menu_locations = array();
if ( current_theme_supports( 'menus' ) ) {
$locations = get_registered_nav_menus();
if ( $locations ) {
$menu_item_locations = array();
foreach ( $locations as $location => $title ) {
$menu_item_locations[ $location ] = $title;
}
$menu_locations = array(
array(
'name' => 'mini_wallet_display_location',
'label' => __( 'Mini wallet display location', 'woo-wallet' ),
'desc' => __( 'Select the location where you want to display mini wallet.', 'woo-wallet' ),
'type' => 'select',
'options' => $menu_item_locations,
'size' => 'regular-text wc-enhanced-select',
'multiple' => true,
),
);
}
}
return $menu_locations;
}
/**
* Get all editable roles.
*/
public function get_editable_role_options() {
$role_options = array();
$editable_roles = array_reverse( wp_roles()->roles );
foreach ( $editable_roles as $role => $details ) {
$name = translate_user_role( $details['name'] );
$role_options[ $role ] = $name;
}
return $role_options;
}
/**
* Callback fuction of all option after save
*
* @param array $old_value old_value.
* @param array $value value.
* @param string $option option.
*/
public function update_option__wallet_settings_general_callback( $old_value, $value, $option ) {
$old_value = is_array( $old_value ) ? $old_value : array();
$value = is_array( $value ) ? $value : array();
if ( isset( $value['product_title'] ) ) {
$old_title = isset( $old_value['product_title'] ) ? $old_value['product_title'] : null;
if ( $old_title !== $value['product_title'] ) {
$this->set_rechargeable_product_title( $value['product_title'] );
}
}
if ( isset( $value['_tax_status'], $value['_tax_class'] ) ) {
$this->set_rechargeable_tax_status( $value['_tax_status'], $value['_tax_class'] );
}
if ( isset( $value['product_image'] ) ) {
$old_image = isset( $old_value['product_image'] ) ? $old_value['product_image'] : null;
if ( $old_image !== $value['product_image'] ) {
$this->set_rechargeable_product_image( $value['product_image'] );
}
}
}
/**
* Set rechargeable product title
*
* @param string $title title.
* @return boolean | int
*/
public function set_rechargeable_product_title( $title ) {
$wallet_product = get_wallet_rechargeable_product();
if ( $wallet_product ) {
$wallet_product->set_name( $title );
return $wallet_product->save();
}
return false;
}
/**
* Set rechargeable tax status
*
* @param string $_tax_status Tax status.
* @param string $_tax_class Tax class.
* @return boolean | int
*/
public function set_rechargeable_tax_status( $_tax_status, $_tax_class ) {
$wallet_product = get_wallet_rechargeable_product();
if ( $wallet_product ) {
$wallet_product->set_tax_status( $_tax_status );
$wallet_product->set_tax_class( $_tax_class );
return $wallet_product->save();
}
return false;
}
/**
* Set rechargeable product image
*
* @param int $attachment_id attachment_id.
* @return boolean | int
*/
public function set_rechargeable_product_image( $attachment_id ) {
$wallet_product = get_wallet_rechargeable_product();
if ( $wallet_product ) {
$wallet_product->set_image_id( $attachment_id );
return $wallet_product->save();
}
return false;
}
}
endif;
// Only auto-instantiate in admin context; REST controller loads this file and
// creates its own instance, so we guard here to avoid duplicate hook registrations.
if ( is_admin() ) {
new Woo_Wallet_Settings( woo_wallet()->settings_api );
}