Generate gift cards when an order moves to Processing

Generate gift card codes when an order moves to Processing.

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, Gift Card codes are generated when:

  • the order is set to Completed or;
  • the order has been successfully paid for.

Add this code to also generate gift cards when an order moves to Processing:

add_action( 'init', 'sw_gc_create_gift_cards_on_processing' );

/**
 * Generate gift cards when an order moves to Processing.
 */
function sw_gc_create_gift_cards_on_processing() {
	add_action( 'woocommerce_order_status_processing', array( 'WC_GC_Gift_Card_Product', 'create_order_gift_cards' ), 10, 2 );
}

Important: Use this only if your payment workflow confirms payment before an order moves to Processing. Moving an order to Processing manually can generate a gift card even if you have not received payment.

Verify the change

↑ Back to top

On a test order, move an order to Processing only after confirming payment is complete, then confirm a gift card code is generated.

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.