Set a fixed expiration time for gift cards

Set a fixed expiration time for gift cards generated from orders.

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.

Use this filter to set the same expiration time for gift cards created from orders. This example uses December 31, 2030 at 23:59 UTC. Replace it with a future date and time that suits your store before using the code.

<?php
add_filter( 'woocommerce_gc_create_order_giftcard_args', 'custom_gift_card_expiration' );

/**
 * Set a fixed expiration time for gift cards generated from orders.
 *
 * @param array $args Gift card creation arguments.
 * @return array Updated arguments.
 */
function custom_gift_card_expiration( $args ) {
	$args['expire_date'] = strtotime( '2030-12-31 23:59:00 UTC' );
	return $args;
}

Review and update the date before it passes. A fixed expiration time also applies to cards scheduled for later delivery, so a card may expire before it is delivered if its delivery date is after the cutoff. This filter affects cards generated from orders; it does not change existing cards.

Verify the change

↑ Back to top

On a staging site, purchase a gift card and confirm its expiration time matches the configured time. Also test a card scheduled for delivery and confirm it expires after delivery.

Questions and support

↑ Back to top

Something 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.

Related Products

Offer Royal Mail shipping rates to your customers.

Notify customers when your products are restocked.

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.