The number field allow me to add
-
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)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘The number field allow me to add ’ is closed to new replies.