v1.0-release

This commit is contained in:
Yuri
2025-11-18 23:16:28 +01:00
parent 271960206c
commit 0b15c1cbf7
6 changed files with 258 additions and 9 deletions
@@ -137,6 +137,46 @@ class WHMCS_Pricing_Admin {
)
);
add_settings_field(
'decimal_separator',
__('Decimal Separator', 'whmcs-pricing'),
array($this, 'render_select_field'),
'whmcs-pricing',
'whmcs_pricing_display_section',
array(
'name' => 'decimal_separator',
'options' => array(
'.' => __('Period (.) - Example: 1,234.56', 'whmcs-pricing'),
',' => __('Comma (,) - Example: 1.234,56', 'whmcs-pricing')
),
'description' => __('Choose the character to use as decimal separator', 'whmcs-pricing')
)
);
add_settings_field(
'hide_currency_symbol',
__('Hide Currency Symbol', 'whmcs-pricing'),
array($this, 'render_checkbox_field'),
'whmcs-pricing',
'whmcs_pricing_display_section',
array(
'name' => 'hide_currency_symbol',
'label' => __('Hide currency symbol/prefix from prices', 'whmcs-pricing')
)
);
add_settings_field(
'hide_billing_cycle',
__('Hide Billing Cycle', 'whmcs-pricing'),
array($this, 'render_checkbox_field'),
'whmcs-pricing',
'whmcs_pricing_display_section',
array(
'name' => 'hide_billing_cycle',
'label' => __('Hide billing cycle text (e.g., "per month") from prices', 'whmcs-pricing')
)
);
// Performance Settings Section
add_settings_section(
'whmcs_pricing_performance_section',
@@ -439,6 +479,28 @@ class WHMCS_Pricing_Admin {
<?php
}
public function render_select_field($args) {
$settings = get_option('whmcs_pricing_settings', array());
$value = isset($settings[$args['name']]) ? $settings[$args['name']] : '';
// Set default value if not set
if (empty($value) && isset($args['default'])) {
$value = $args['default'];
}
?>
<select name="whmcs_pricing_settings[<?php echo esc_attr($args['name']); ?>]" class="regular-text">
<?php foreach ($args['options'] as $option_value => $option_label): ?>
<option value="<?php echo esc_attr($option_value); ?>" <?php selected($value, $option_value); ?>>
<?php echo esc_html($option_label); ?>
</option>
<?php endforeach; ?>
</select>
<?php if (isset($args['description'])): ?>
<p class="description"><?php echo esc_html($args['description']); ?></p>
<?php endif; ?>
<?php
}
public function render_currency_field($args) {
$settings = get_option('whmcs_pricing_settings', array());
$value = isset($settings[$args['name']]) ? $settings[$args['name']] : 'USD';
@@ -464,7 +526,8 @@ class WHMCS_Pricing_Admin {
'SGD' => 'SGD - Singapore Dollar (S$)',
'NZD' => 'NZD - New Zealand Dollar (NZ$)',
'MXN' => 'MXN - Mexican Peso (Mex$)',
'ZAR' => 'ZAR - South African Rand (R)'
'ZAR' => 'ZAR - South African Rand (R)',
'ARS' => 'ARS - Argentine Peso ($)'
);
?>
<select name="whmcs_pricing_settings[<?php echo esc_attr($args['name']); ?>]" class="regular-text">
@@ -492,7 +555,7 @@ class WHMCS_Pricing_Admin {
}
// Sanitize text fields
$text_fields = array('api_identifier', 'api_secret', 'default_currency');
$text_fields = array('api_identifier', 'api_secret', 'default_currency', 'decimal_separator');
foreach ($text_fields as $field) {
if (isset($input[$field])) {
$sanitized[$field] = sanitize_text_field($input[$field]);
@@ -506,6 +569,8 @@ class WHMCS_Pricing_Admin {
// Sanitize checkboxes
$sanitized['show_decimals'] = isset($input['show_decimals']) ? true : false;
$sanitized['hide_currency_symbol'] = isset($input['hide_currency_symbol']) ? true : false;
$sanitized['hide_billing_cycle'] = isset($input['hide_billing_cycle']) ? true : false;
$sanitized['debug_mode'] = isset($input['debug_mode']) ? true : false;
return $sanitized;
+11 -3
View File
@@ -23,6 +23,9 @@ class WHMCS_Pricing_API {
'cache_duration' => 3600,
'default_currency' => 'USD',
'show_decimals' => true,
'decimal_separator' => '.',
'hide_currency_symbol' => false,
'hide_billing_cycle' => false,
'debug_mode' => false
);
@@ -227,12 +230,16 @@ class WHMCS_Pricing_API {
private static function format_price($price, $currency, $format) {
$settings = self::get_settings();
// Get decimal separator from settings (default to '.')
$decimal_sep = isset($settings['decimal_separator']) ? $settings['decimal_separator'] : '.';
$thousands_sep = ($decimal_sep === '.') ? ',' : '.';
// Apply decimal formatting
if ($format === 'no_decimals' || !$settings['show_decimals']) {
$price = round($price);
$formatted_price = number_format($price, 0);
$formatted_price = number_format($price, 0, $decimal_sep, $thousands_sep);
} else {
$formatted_price = number_format($price, 2);
$formatted_price = number_format($price, 2, $decimal_sep, $thousands_sep);
}
// Get currency symbol
@@ -271,7 +278,8 @@ class WHMCS_Pricing_API {
'SGD' => 'S$',
'NZD' => 'NZ$',
'MXN' => 'Mex$',
'ZAR' => 'R'
'ZAR' => 'R',
'ARS' => '$'
);
return isset($symbols[$currency]) ? $symbols[$currency] : $currency;
+17 -4
View File
@@ -130,6 +130,16 @@ class WHMCS_Pricing_Shortcodes {
$classes[] = $custom_class;
}
// Get global settings
$settings = get_option('whmcs_pricing_settings', array());
$hide_currency_symbol = isset($settings['hide_currency_symbol']) && $settings['hide_currency_symbol'];
$hide_billing_cycle = isset($settings['hide_billing_cycle']) && $settings['hide_billing_cycle'];
// Override billing cycle display based on global setting
if ($hide_billing_cycle) {
$show_cycle = false;
}
$cycle_text = $show_cycle ? $this->get_cycle_text($billing_cycle, $lang) : '';
$html = sprintf(
@@ -139,10 +149,13 @@ class WHMCS_Pricing_Shortcodes {
esc_attr($billing_cycle)
);
$html .= sprintf(
'<span class="currency-symbol">%s</span>',
esc_html($price_data['symbol'])
);
// Only show currency symbol if not hidden
if (!$hide_currency_symbol) {
$html .= sprintf(
'<span class="currency-symbol">%s</span>',
esc_html($price_data['symbol'])
);
}
$html .= sprintf(
'<span class="price-amount">%s</span>',