Woocommerce different URL for every table placed in the restaurant

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.

Leave a Comment