If a checkbox is checked, it saves a value of 1 for a 'my_checkbox' custom order field in WooCommerce. I'm editing the order admin table and I need to be able to echo a particular icon url if the value of 'my_checkbox' equals 1. I just don't know how to check if the value is equal to one so I can echo the url. Any ideas?
To make troubleshooting easier, here's the code:
/**
* Add checkbox field to the checkout
**/
add_action('woocommerce_after_checkout_billing_form', 'match_previous_order_checkbox');
function match_previous_order_checkbox( $checkout ) {
echo '<div id="match_the_order">';
woocommerce_form_field( 'my_checkbox', array(
'type' => 'checkbox',
'class' => array('form-row notes'),
'label' => __( 'This is a previous order' , 'woothemes'),
'required' => false,
),
$checkout->get_value( 'my_checkbox' ));
echo '</div>';
}
/**
* Update the order meta with field value
**/
add_action('woocommerce_checkout_update_order_meta', 'match_order_checkout_field_update_order_meta');
function match_order_checkout_field_update_order_meta( $order_id ) {
if ($_POST['my_checkbox']) {
update_post_meta( $order_id, 'My_Checkbox', esc_attr($_POST['my_checkbox']));
}
}
global $order;
$match_order_meta = get_post_meta( $order_id , 'My_Checkbox' );
$match_order_meta = get_post_meta( $order->ID , 'My_Checkbox' );
doesn't work either. Also whether or not I include global $order;
doesn't seem to matter.