Redeem happpen twice
-
Theme: Twenty Twenty-Four
Plugins:
WooCommerce
WooCommerce Stripe Gateway
YITH WooCommerce Gift CardsTwo issues:
- When using a giftcard in the cart it instantly removes the amount from the giftcard, but if i remove the giftcard again its not added the value back to the giftcard
- Again when adding the gifcard in the cart, its removed from the value. BUT when i press place order. It removed the same value again. Tested with order where the value is zero after using a giftcard.
Soi its uses the value twice.
-
Note. The stripe gatewayu is not in use when order value is zero.
Just some notes:
it doesnt look like the functions/* Ajax action for applying a gift card to the cart */ add_action( 'wp_ajax_ywgc_apply_gift_card_code', array( $this, 'apply_gift_card_code_callback' ) ); add_action( 'wp_ajax_nopriv_ywgc_apply_gift_card_code', array( $this, 'apply_gift_card_code_callback' ) );
Are being used at all and might caseu the issues because it doesn’t know the codes are applied already.
Hello there,
we hope you’re doing well!Do you only have those 3 plugins active when doing the test? If so, what happens if you deactivate Stripe?
Please let me know.
Best regards.
For testing its only thoose 3. Its the same issue even with Stripe off. Here is a test with only the absolute required: Made a video here: https://youtu.be/mj1Lqc5zySs
It simply doesnt know it allready have them added and the functions to do it look like they arent even activated.
Hello there,
After reviewing your video I was able to reproduce the error. This is due to WooCommerce blocks, where an order is created in draft status without even having finalized the order. This functionality belongs to WooCommerce so we will have to check if it is possible to solve it.
In the meantime, you can use the [woocommerce_checkout] shortcode on the checkout page, instead of the WooCommerce blocks.
As soon as we have news we will let you know, thank you for your report.
Best regards.
The double redeem issue works after using the shortcode, but refunding doesnt seem to work still. (possible still the functions to save the applied giftcards on the order that isnt working)
Hello there,
Please try adding the following code in the functions.php file of your active theme and check if it solves the problem:
/** * Override YITH Gift Card deduction on draft orders * */
if ( ! function_exists( 'override_yith_giftcard_deduction' ) ) {
add_action('woocommerce_new_order_item', 'override_yith_giftcard_deduction', 999, 3);
function override_yith_giftcard_deduction($item_id, $item, $order_id) {
if ($item instanceof WC_Order_Item_Coupon) {
// get the order
$order = wc_get_order($order_id);
// if the order is draft, add the amount back to the gift card
if ($order->get_status() == 'checkout-draft') {
$code = $item->get_code();
$gift = YITH_YWGC()->get_gift_card_by_code($code);
if ($gift instanceof YITH_YWGC_Gift_Card) {
$discount_amount = $item->get_discount();
$gift->update_balance($gift->get_balance() + $discount_amount);
}
}
}
}
}
/** * Deduct after the order is placed */
if ( ! function_exists( 'override_yith_giftcard_deduction' ) ) {
add_action('woocommerce_payment_complete', 'deduct_gift_card_balance', 10, 3);
function deduct_gift_card_balance($order_id) {
// Get the order
$order = wc_get_order($order_id);
// If the order contains coupons, deduct the amount from the gift card
if ($order->get_coupon_codes()) {
foreach ($order->get_coupon_codes() as $code) {
$gift = YITH_YWGC()->get_gift_card_by_code($code);
if ($gift instanceof YITH_YWGC_Gift_Card) {
// Calculate the discount amount for this coupon
$discount_amount = 0;
foreach ($order->get_items('coupon') as $coupon_item) {
if ($coupon_item->get_code() === $code) {
$discount_amount += $coupon_item->get_discount();
}
}
$gift->update_balance($gift->get_balance() - $discount_amount);
}
}
}
}
}Let us know any news.
Best regards.
Which problem should this code fix? The original one or the lack of refund?
Hello there,
What exactly do you mean by refund? The above code fixes the problem with WooCommerce blocks, and prevents the gift card balance from being deducted if the purchase process is not completed, since with WooCommerce blocks an order is created in draft status during checkout regardless of whether the purchase is completed or not.
Let us know any news.
Best regards.
With your new code, it doesnt look like it works. It stopps removing several times, but now it doesnt remove it at all.
Hello there,
Please try replacing the second portion of the last code with this new one:
if (!function_exists('override_yith_giftcard_deduction')) {
? ? add_action('woocommerce_order_payment_status_changed', 'deduct_gift_card_balance', 10, 3);
? ? function deduct_gift_card_balance($order_id, $new_status, $old_status)
? ? {
? ? ? ? if ( 'checkout-draft' == $old_status && ( 'processing' == $new_status || 'completed' == $new_status ) )
? ? ? ? // Get the order
? ? ? ? $order = wc_get_order($order_id);
? ? ? ? // If the order contains coupons, deduct the amount from the gift card
? ? ? ? if ($order->get_coupon_codes()) {
? ? ? ? ? ? foreach ($order->get_coupon_codes() as $code) {
? ? ? ? ? ? ? ? $gift = YITH_YWGC()->get_gift_card_by_code($code);
? ? ? ? ? ? ? ? if ($gift instanceof YITH_YWGC_Gift_Card) {
? ? ? ? ? ? ? ? ? ? // Calculate the discount amount for this coupon
? ? ? ? ? ? ? ? ? ? $discount_amount = 0;
? ? ? ? ? ? ? ? ? ? foreach ($order->get_items('coupon') as $coupon_item) {
? ? ? ? ? ? ? ? ? ? ? ? if ($coupon_item->get_code() === $code) {
? ? ? ? ? ? ? ? ? ? ? ? ? ? $discount_amount += $coupon_item->get_discount();
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? $gift->update_balance($gift->get_balance() - $discount_amount);
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? }
? ? }
}If it still doesn’t work, please try using the shortcode instead of the checkout block.
Let us know any news.
Best regards.
When applying the code in cart it removed the value from the giftcard for a couple of seconds. Then the value is back to what it was.
When placing order it does not remove the value Again.
When using woocommerce_cart . the value is not removed when applying in cart. But is removed from the value when checking out when woocommerce_checkut is used.
So it still doenst Work with the default Woocommerce.
- You must be logged in to reply to this topic.