I have a similar problem to an issue raised on an older thread here:
Woocommerce different URL for every table placed in the restaurant
I am trying to adapt Woocommerce to a in-restaurant ordering system so that every table in it will have a unique qr on it from which a customer will scan, the menu will open and the guest will place his/her order. The qr codes will direct to a url which will pass in a variable string, then will be picked up by a php get and later retreived into a check-out field of Woocommerce. That way the customer will not have to enter his/her table number manually.
I have added the following code to a test site at http://niyazib1.sg-host.com/ and accessed it using a variable url such as http://niyazib1.sg-host.com/store?dining=25 but the table number field at the check out page remains empty. I tried clearing and disabling cache too. Could you please check the site and tell me what is missing? Thanks.
code // Store session value for table number
add_action('init', 'store_table_number');
function store_table_number() {
if( $_GET['dining'] ) {
global $tableNo;
$tableNo = array( 'number' => $_GET['dining'] );
}
}
// Add Table Number field to checkout
add_filter( 'woocommerce_checkout_fields' , 'table_number_checkout' );
function table_number_checkout( $fields ) {
$fields['order']['table_number'] = array(
'label' => __('Table Number', 'woocommerce'),
'placeholder' => _x('Table', 'placeholder', 'woocommerce'),
'value' => $GLOBALS['tableNo']['number'],
'required' => false,
'class' => array('form-row-wide'),
'clear' => true
);
return $fields;
}
// Output table number in WP Admin panel
add_action( 'woocommerce_admin_order_data_after_shipping_address', 'table_number_admin', 10, 1 );
function table_number_admin($order){
echo '<p><strong>'.__('Table Number').':</strong> ' . get_post_meta( $order->get_id(), '_table_number', true ) . '</p>';
}