Plugin Directory

Changeset 3311229


Ignore:
Timestamp:
06/13/2025 07:29:52 PM (10 months ago)
Author:
digihold
Message:

Update

Location:
digicommerce/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • digicommerce/trunk/digicommerce.php

    r3310934 r3311229  
    437437            $table_name = $wpdb->prefix . 'digicommerce';
    438438
    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' ) {
    441441                $this->options[ $key ] = $value;
    442442
  • digicommerce/trunk/includes/admin/class-digicommerce-product.php

    r3308154 r3311229  
    708708        $currency          = DigiCommerce()->get_option( 'currency', 'USD' );
    709709        $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' );
    710713
    711714        // Ensure the price is numeric
     
    714717        // Format the price without forcing decimal places
    715718        $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>';
    718721
    719722        $currency_symbol = $plain
  • digicommerce/trunk/includes/admin/class-digicommerce-settings.php

    r3291782 r3311229  
    110110            'type'              => 'array',
    111111            'sanitize_callback' => array( $this, 'sanitize_social_links' ),
     112        );
     113
     114        $separator = array(
     115            'type'              => 'string',
     116            'sanitize_callback' => array( $this, 'sanitize_separator_callback' ),
    112117        );
    113118
     
    123128        register_setting( 'digicommerce_options', 'digicommerce_currency', $text ); // phpcs:ignore
    124129        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
    125133        register_setting( 'digicommerce_options', 'digicommerce_block_admin', $bool ); // phpcs:ignore
    126134        register_setting( 'digicommerce_options', 'digicommerce_redirect_login', $bool ); // phpcs:ignore
     
    274282
    275283    /**
     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    /**
    276296     * Process form submission
    277297     */
     
    301321            'currency'                    => sanitize_text_field( $_POST['currency'] ), // phpcs:ignore
    302322            '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
    303326            'block_admin'                 => isset( $_POST['block_admin'] ) ? 1 : 0, // phpcs:ignore
    304327            'redirect_login'              => isset( $_POST['redirect_login'] ) ? 1 : 0, // phpcs:ignore
     
    794817                        <option value="right_space" <?php selected( $options['currency_position'], 'right_space' ); ?>><?php esc_html_e( 'Right with space', 'digicommerce' ); ?></option>
    795818                    </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>
    796834                </p>
    797835            </div>
     
    18171855            'currency'                    => DigiCommerce()->get_option( 'currency', 'USD' ),
    18181856            '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' ),
    18191860            'block_admin'                 => DigiCommerce()->get_option( 'block_admin', false ),
    18201861            'redirect_login'              => DigiCommerce()->get_option( 'redirect_login', false ),
Note: See TracChangeset for help on using the changeset viewer.