Skip to content

Instantly share code, notes, and snippets.

@xlplugins
Created April 3, 2025 11:56
Show Gist options
  • Save xlplugins/daa3af57c25fc7e10a62902bcf38fdcf to your computer and use it in GitHub Desktop.
Save xlplugins/daa3af57c25fc7e10a62902bcf38fdcf to your computer and use it in GitHub Desktop.
Save engraving meta to order
add_action( 'woocommerce_checkout_create_order', function ( $order, $data ) {
/**
* @var $order WC_Order;
*/
$have_engraving = null;
foreach ( WC()->cart->get_cart_contents() as $cart_item_key => $cart_item ) {
if ( ! isset( $cart_item['wapf'] ) ) {
continue;
}
foreach ( $cart_item['wapf'] as $addon ) {
if ( isset( $addon['label'] ) && ! empty( $addon['label'] ) && false !== strpos( $addon['label'], 'Custom Engraving' ) ) {
if ( ! empty( $addon['values'] ) ) {
$order->add_meta_data( 'funnelkit_engraving', 'yes' );
return;
}
break;
}
}
}
$order->add_meta_data( 'funnelkit_engraving', 'no' );
}, 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment