Thanks Flavia!
I’ve tried this without success.
This is how I add the field and save it on order:
add_action('woocommerce_after_order_notes', 'cc_add_checkout_field');
function cc_add_checkout_field($checkout)
{
echo '<div id="gift_name_checkout_field"><h2>' . __('GiftField') . '</h2>';
woocommerce_form_field('gift_name', array(
'type' => 'text',
'class' => array('gift-name'),
'label' => __('Gift name'),
'placeholder' => __(''),
), $checkout->get_value('gift_name'));
echo '</div>';
}
add_action('woocommerce_checkout_update_order_meta', 'cc_checkout_field_update_order_meta');
function cc_checkout_field_update_order_meta($order_id)
{
if (!empty($_POST['gift_name'])) {
update_post_meta($order_id, 'GiftField', sanitize_text_field($_POST['gift_name']));
}
}
The field is saved successfully when the order is completed.
The trigger is launched, and on the action I try to create the user, using this field. I’ve tried with:
– {1:post_meta:GiftName}
– {1:post_meta:gift_name}
with no results.
Maybe I’m forgetting to do something.