Pardon the PHP noob question... I have added a custom checkbox for gift wrapping to my woocommerce cart. I am able to get the value to return to the "orders" page in a custom meta box and in the order summary, but I can only get the value to return as null or "1". I'd like to return a value of "yes" or "no". Thanks in advance for any advice.
HERE'S THE CODE I'M USING IN MY FUNCTIONS.PHP (CUSTOMIZED FROM THE WOOCOMMERCE DOCUMENTATION):
/Add Gift Wrapping field to the checkout/
add_action('woocommerce_after_order_notes', 'gift_wrapping_field');
function gift_wrapping_field( $checkout )
{
woocommerce_form_field( 'gift_wrapping', array(
'type' => 'checkbox',
'class' => array('input-checkbox'),
'label' => __('Include Free Gift Wrapping'),
'required' => false,
), $checkout->get_value( 'gift_wrapping' ));
}
/Process the checkout/
add_action('woocommerce_checkout_process', 'gift_wrapping_field_process');
function my_custom_checkout_field_process()
{
global $woocommerce;
// Check if set, if its not set add an error.
if (!$_POST['terms_conditions'])
$woocommerce->add_error( __('Please agree to terms and conditions.') );
}
/Update the order meta with field value/
add_action('woocommerce_checkout_update_order_meta', 'gift_wrapping_field_update_order_meta');
function gift_wrapping_field_update_order_meta( $order_id )
{
if ($_POST['gift_wrapping']) update_post_meta( $order_id, 'Include Free Gift Wrapping', esc_attr($_POST['gift_wrapping']));
}
/*Update the order summary with field value*/
add_action( 'woocommerce_admin_order_data_after_billing_address', 'my_custom_checkout_field_display_admin_order_meta', 10, 1 );
function my_custom_checkout_field_display_admin_order_meta($order)
{
echo '<p><strong>'.__('Include Free Gift Wrapping').':</strong> ' . $order->order_custom_fields['Include Free Gift Wrapping'][0] . '</p>';
}
AND HERE'S A SCREENSHOT OF WHAT'S BEING RETURNED TO THE ADMIN FROM THE FORM RESULTS:
