Choose which characters can be used when generating gift card codes.
Note:
This is a Developer level doc. If you are unfamiliar working with code and resolving potential conflicts, we recommend you work with a Woo Agency Partner for larger projects, or find a WooCommerce developer on Codeable for smaller customizations. We are unable to provide support for customizations under our Support Policy.
Test custom code on a staging site before using it on your store. Add PHP to a custom plugin or a child theme’s functions.php file. If the file is already inside a PHP block, omit the opening PHP tag.
By default, the characters used to generate Gift Card codes are ABCDEFGHJKLMNPQRSTUVWXYZ23456789.
This example removes Z from the default set. Change the returned string to the characters you want to use. Keep a large character set: reducing it makes codes easier to guess.
add_filter( 'wc_gc_gift_card_code_characters_source', 'sw_gc_custom_codes' );
/**
* Choose the characters used for new gift card codes.
*
* @return string Characters available for code generation.
*/
function sw_gc_custom_codes() {
return 'ABCDEFGHJKLMNPQRSTUVWXY23456789';
}
Verify the change
↑ Back to topCreate test gift cards and confirm their codes use only the characters in the configured source.
Questions and support
↑ Back to topSomething missing from this documentation? Still have questions and need assistance?
- If you have a question about a specific extension or theme you’d like to purchase, contact us to get answers.
- If you already purchased this product and need some assistance, get in touch with a Happiness Engineer via our support page and select this product’s name from the Product dropdown.