Created
March 4, 2025 05:35
-
-
Save shameemreza/bcf821abe035713bde42c20c668cd256 to your computer and use it in GitHub Desktop.
Retrieve the WooCommerce Gift Card Code in AutomateWoo: https://woocommerce.com/products/gift-cards/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Inside AutomateWoo, use the variable: {custom_function.aw_get_gift_card_code} to include the gift card code in the email. | |
# The gift card codes are stored as order item meta data. | |
function aw_get_gift_card_code( $workflow ) { | |
$order = $workflow->data_layer()->get_order(); | |
foreach ( $order->get_items() as $item ) { | |
if ( $item->get_product()->is_type( 'gift-card' ) ) { | |
$gift_card_code = $item->get_meta( '_wc_gc_giftcard_code', true ); | |
if ( ! empty( $gift_card_code ) ) { | |
return $gift_card_code; | |
} | |
} | |
} | |
return ''; | |
} | |
add_filter( 'automatewoo/custom_function/aw_get_gift_card_code', 'aw_get_gift_card_code', 10, 1 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment