Product Icon

Gift Cards for WooCommerce

Offer prepaid digital gift cards that customers can redeem online.

Allow custom validation when a gift card is applied

Add a filter hook that runs before a card code is applied at cart or at checkout. This should allow developers to perform their own custom validation before a card is applied to an order. I am working on a website that has multiple currencies and I want only allow users to use cards in the same currency as they were purchased in. For example if a card was purchased using Euro, and a user tries to use that card while they have selected GBP, my custom validation will not allow that.

In my test environment I modified you plugin and added a hook in file: /woocommrce-gift-cards/includes/class-wc-gc-cart.php
Function: process_gift_card_cart_form

My code is this (See screenshot):
if( ! apply_filters( ‘custom_gift_card_validation’, true, $args ) ){
$this->notices[] = array( ‘text’ => __( ‘Invalid gift card’, ‘woocommerce-gift-cards’ ), ‘type’ => ‘notice’ );
return false;
}

This hook allows me to perform custom validation as explained above. There may be another better place to add this hook, but that is the only place I could find.

Screenshots

Author

zeb2cubedie

Current Status

Open

Last updated: November 26, 2024

0 comments

Log in to comment on this feature request.

Use of your personal data
We and our partners process your personal data (such as browsing data, IP Addresses, cookie information, and other unique identifiers) based on your consent and/or our legitimate interest to optimize our website, marketing activities, and your user experience.