public function wpr_decrease_balance($giftCard_id) { $newBalance = wpr_get_giftcard_balance($giftCard_id) - $this->wpr_get_payment_amount(); wpr_set_giftcard_balance($giftCard_id, $newBalance); // Check if the gift card ballance is 0 and if it is change the post status to zerobalance if (wpr_get_giftcard_balance($giftCard_id) == 0) { wpr_update_giftcard_status($giftCard_id, 'zerobalance'); } }
/** * Updates the Gift Card and the order information when the order is processed * */ function rpgc_update_card($order_id) { global $woocommerce; $giftCard_id = WC()->session->giftcard_post; if ($giftCard_id != '') { $newBalance = wpr_get_giftcard_balance($giftCard_id) - WC()->session->giftcard_payment; // Check if the gift card ballance is 0 and if it is change the post status to zerobalance if (wpr_get_giftcard_balance($giftCard_id) == 0) { wpr_update_giftcard_status($giftCard_id, 'zerobalance'); } $giftCard_IDs = get_post_meta($giftCard_id, 'wpr_existingOrders_id', true); $giftCard_IDs[] = $order_id; update_post_meta($giftCard_id, 'rpgc_balance', $newBalance); // Update balance of Giftcard update_post_meta($giftCard_id, 'wpr_existingOrders_id', $giftCard_IDs); // Saves order id to gifctard post update_post_meta($order_id, 'rpgc_id', $giftCard_id); update_post_meta($order_id, 'rpgc_payment', WC()->session->giftcard_payment); update_post_meta($order_id, 'rpgc_balance', $newBalance); WC()->session->idForEmail = $order_id; unset(WC()->session->giftcard_payment, WC()->session->giftcard_post); } if (isset(WC()->session->giftcard_data)) { update_post_meta($order_id, 'rpgc_data', WC()->session->giftcard_data); unset(WC()->session->giftcard_data); } }