Changeset 3311229
- Timestamp:
- 06/13/2025 07:29:52 PM (10 months ago)
- Location:
- digicommerce/trunk
- Files:
-
- 3 edited
-
digicommerce.php (modified) (1 diff)
-
includes/admin/class-digicommerce-product.php (modified) (2 diffs)
-
includes/admin/class-digicommerce-settings.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
digicommerce/trunk/digicommerce.php
r3310934 r3311229 437 437 $table_name = $wpdb->prefix . 'digicommerce'; 438 438 439 // Only proceed if the value is not empty 440 if ( ! empty( $value ) ) {439 // Only proceed if the value is not empty (but allow 0) 440 if ( ! empty( $value ) || $value === 0 || $value === '0' ) { 441 441 $this->options[ $key ] = $value; 442 442 -
digicommerce/trunk/includes/admin/class-digicommerce-product.php
r3308154 r3311229 708 708 $currency = DigiCommerce()->get_option( 'currency', 'USD' ); 709 709 $currency_position = DigiCommerce()->get_option( 'currency_position', 'left' ); 710 $thousand_sep = DigiCommerce()->get_option( 'thousand_sep', ',' ); 711 $decimal_sep = DigiCommerce()->get_option( 'decimal_sep', '.' ); 712 $num_decimals = (int) DigiCommerce()->get_option( 'num_decimals', '2' ); 710 713 711 714 // Ensure the price is numeric … … 714 717 // Format the price without forcing decimal places 715 718 $formatted_price = $plain 716 ? number_format( $numeric_price, 2)717 : '<span class="price">' . number_format( $numeric_price, 2) . '</span>';719 ? number_format( $numeric_price, $num_decimals, $decimal_sep, $thousand_sep ) 720 : '<span class="price">' . number_format( $numeric_price, $num_decimals, $decimal_sep, $thousand_sep ) . '</span>'; 718 721 719 722 $currency_symbol = $plain -
digicommerce/trunk/includes/admin/class-digicommerce-settings.php
r3291782 r3311229 110 110 'type' => 'array', 111 111 'sanitize_callback' => array( $this, 'sanitize_social_links' ), 112 ); 113 114 $separator = array( 115 'type' => 'string', 116 'sanitize_callback' => array( $this, 'sanitize_separator_callback' ), 112 117 ); 113 118 … … 123 128 register_setting( 'digicommerce_options', 'digicommerce_currency', $text ); // phpcs:ignore 124 129 register_setting( 'digicommerce_options', 'digicommerce_currency_position', $text ); // phpcs:ignore 130 register_setting( 'digicommerce_options', 'digicommerce_thousand_sep', $separator ); // phpcs:ignore 131 register_setting( 'digicommerce_options', 'digicommerce_decimal_sep', $separator ); // phpcs:ignore 132 register_setting( 'digicommerce_options', 'digicommerce_num_decimals', $text ); // phpcs:ignore 125 133 register_setting( 'digicommerce_options', 'digicommerce_block_admin', $bool ); // phpcs:ignore 126 134 register_setting( 'digicommerce_options', 'digicommerce_redirect_login', $bool ); // phpcs:ignore … … 274 282 275 283 /** 284 * Sanitize separator fields (thousand_sep, decimal_sep). 285 * 286 * @param string $input Separator to sanitize. 287 * @return string 288 */ 289 public function sanitize_separator_callback( $input ) { 290 $input = wp_unslash( $input ); 291 $input = trim( $input ); 292 return mb_substr( $input, 0, 1 ); 293 } 294 295 /** 276 296 * Process form submission 277 297 */ … … 301 321 'currency' => sanitize_text_field( $_POST['currency'] ), // phpcs:ignore 302 322 'currency_position' => sanitize_text_field( $_POST['currency_position'] ), // phpcs:ignore 323 'thousand_sep' => $this->sanitize_separator_callback( $_POST['thousand_sep'] ?? '' ), // phpcs:ignore 324 'decimal_sep' => $this->sanitize_separator_callback( $_POST['decimal_sep'] ?? '' ), // phpcs:ignore 325 'num_decimals' => absint( $_POST['num_decimals'] ), // phpcs:ignore 303 326 'block_admin' => isset( $_POST['block_admin'] ) ? 1 : 0, // phpcs:ignore 304 327 'redirect_login' => isset( $_POST['redirect_login'] ) ? 1 : 0, // phpcs:ignore … … 794 817 <option value="right_space" <?php selected( $options['currency_position'], 'right_space' ); ?>><?php esc_html_e( 'Right with space', 'digicommerce' ); ?></option> 795 818 </select> 819 </p> 820 <p class="flex flex-col gap-2"> 821 <label class="cursor-pointer" for="thousand_sep"><?php esc_html_e( 'Thousand Separator', 'digicommerce' ); ?></label> 822 <input type="text" id="thousand_sep" name="thousand_sep" value="<?php echo esc_attr( $options['thousand_sep'] ); ?>" class="regular-text" style="width:5rem;min-width:5rem"> 823 <small><?php esc_html_e( 'Set the thousand separator of displayed prices.', 'digicommerce' ); ?></small> 824 </p> 825 <p class="flex flex-col gap-2"> 826 <label class="cursor-pointer" for="decimal_sep"><?php esc_html_e( 'Decimal Separator', 'digicommerce' ); ?></label> 827 <input type="text" id="decimal_sep" name="decimal_sep" value="<?php echo esc_attr( $options['decimal_sep'] ); ?>" class="regular-text" style="width:5rem;min-width:5rem"> 828 <small><?php esc_html_e( 'Set the decimal separator of displayed prices.', 'digicommerce' ); ?></small> 829 </p> 830 <p class="flex flex-col gap-2"> 831 <label class="cursor-pointer" for="num_decimals"><?php esc_html_e( 'Number Of Decimals', 'digicommerce' ); ?></label> 832 <input type="number" min="0" step="1" id="num_decimals" name="num_decimals" value="<?php echo esc_attr( $options['num_decimals'] ); ?>" class="regular-text" style="width:5rem;min-width:5rem"> 833 <small><?php esc_html_e( 'Set the number of decimal points shown in displayed prices.', 'digicommerce' ); ?></small> 796 834 </p> 797 835 </div> … … 1817 1855 'currency' => DigiCommerce()->get_option( 'currency', 'USD' ), 1818 1856 'currency_position' => DigiCommerce()->get_option( 'currency_position', 'left' ), 1857 'thousand_sep' => DigiCommerce()->get_option( 'thousand_sep', ',' ), 1858 'decimal_sep' => DigiCommerce()->get_option( 'decimal_sep', '.' ), 1859 'num_decimals' => DigiCommerce()->get_option( 'num_decimals', '2' ), 1819 1860 'block_admin' => DigiCommerce()->get_option( 'block_admin', false ), 1820 1861 'redirect_login' => DigiCommerce()->get_option( 'redirect_login', false ),
Note: See TracChangeset
for help on using the changeset viewer.