Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save shameemreza/bcf821abe035713bde42c20c668cd256 to your computer and use it in GitHub Desktop.
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/
# 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