Question

my company is working with different restaurants to digitize their menus so that people dont touch the menu cards in this Covid 19 pandemic, so every table in a restaurant will have a unique qr placed on it, when a customer scans it the menu will open and he can order it from there, the issue i am facing is how to set all those unique urls linked with the table number, and how to show the table number on the dashboard of woocommerce so that the restaurant knows the table number from which the order came. thanks and regards Aetzad

Was it helpful?

Solution

I don't have a WooCommerce currently to test this out on, so it's very rough and ready, and may not even work... But, I think the logic is fairly sound. Give this a go:

// 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>';
}

The above will be added to your functions.php file. The first function starts the session and stores the value of your URL variable. The second adds a table number field to the WooCommerce checkout page, referenced from here. And finally, the third function adds a table number field to the order screen in your WordPress admin, which will ultimately allow you to configure your email output. Again referenced from the above link.

OTHER TIPS

From what you have described, could you not simply pass in a variable in the url string which then gets stored in a session for the guest? Your URL might look something like this:

https://www.therestaurant.com/menu?dining=22

You can then of course retrieve that table number using a PHP get:

$tableNumber = $_GET['dining'];

This would give you the facility to take the user straight to the order / menu page on your site, whilst still storing their table to later send with the form submission to the kitchen and would let you easily add / remove / relabel tables on the fly.

Hope it helps. Ben.

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top