• Resolved levskipg

    (@levskipg)


    I created number field in users and added function that will be calculating how much people spend on shop and add that to that field. But this field adding me

    1 229

    Here is my code:

    // Update 'wydana_kwota' custom field when an order is completed or refunded
    function update_wydana_kwota_custom_field($order_id) {
        $order = wc_get_order($order_id);
        
        if ($order->get_status() === 'completed' || $order->get_status() === 'refunded') {
            $user_id = $order->get_user_id();
            $current_wydana_kwota = (float) get_user_meta($user_id, 'wydana_kwota', true);
            $order_total = (float) $order->get_total(); // Convert to float
            
            if ($order->get_status() === 'completed') {
                // Calculate and update the total amount
                $updated_wydana_kwota = $current_wydana_kwota + $order_total;
            } elseif ($order->get_status() === 'refunded') {
                // Calculate and update the total amount after refund
                $updated_wydana_kwota = $current_wydana_kwota - $order_total;
            }
            
            update_user_meta($user_id, 'wydana_kwota', $updated_wydana_kwota);
        }
    }
    add_action('woocommerce_order_status_completed', 'update_wydana_kwota_custom_field');
    add_action('woocommerce_order_status_refunded', 'update_wydana_kwota_custom_field');
    
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Paul Clark

    (@pdclark)

    Hi @levskipg,

      is likely due to the site language being set to Polish. Here are some details regarding the relevant localization settings and expected behavior of display functions:

    • “Wydana Kwota” is Polish for “Spent Amount”.
    • The thousands separator used in Polish is a space.
    •   is HTML for a space. It stands for “Non-Breaking SPace”. It’s for cases where a space should exist but the values on either side should stick together across lines of text.
    • In the settings of Pods currency and number fields, there is a setting titled Number Format. It can be overridden, but the default value of this field is Localized Default. This means if the site language is set to Polski on /wp-admin/options-general.php, the output of magic tags such as {@wydana_kwota} or pods( 'user', get_current_user_id() )->display( 'wydana_kwota' ); will format the field using a space as the thousands separator and a currency symbol before the number.
    • pods( 'user', get_current_user_id() )->field( 'wydana_kwota' ); or get_user_meta( get_current_user_id(), 'wydana_kwota', true ); should return the unformatted number.
    • The format used by ->display() or magic tags can be changed by modifying the Number Format setting on the currency or number field.
    • WooCommerce also has currency localization settings, which can be found under Currency Options on /wp-admin/admin.php?page=wc-settings&tab=general
    Plugin Author Jory Hogeveen

    (@keraweb)

    Hi @levskipg

    We havent heard from you anymore so I’m closing this topic.
    Feel free to reopen if you still need help!

    Cheers, Jory

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘The number field allow me to add  ’ is closed to new replies.