1. Home
  2. Knowledge Base
  3. WooCommerce Restaurant Ordering
  4. Developer Documentation

Actions and Filters

WooCommerce Restaurant Ordering has a number of hooks and filters which allow you to customize its behavior. This article is aimed at developers.

We've partnered with Codeable to provide our customers with expert help if required.

Filters

wc_restaurant_ordering_navigation_scroll_offset

The amount of 'scroll offset' to apply when a category in the restaurant order form navigation menu is clicked.

The order form will scroll to the selected category, but the position after scrolling can sometimes be incorrect if your website site has a fixed or sticky menu. Use this filter to set an offset, to account for your site's fixed menu. For example, if your sticky menu is 50 pixels high, set this filter to 50.

Arguments / return
int - The amount of scroll offset in pixels. Default: 0

wc_restaurant_ordering_script_params

Filter to modify the parameters passed the to the front-end javascript. The array includes the following keys, with defaults shown on the right.

  • show_cart_notice - set in plugin settings
  • cart_notice_timeout - 2800
  • show_stock_in_modal - set in plugin settings
  • nav_scroll_offset - 0
  • refresh_cart - true
  • price_currency_format - WooCommerce default
  • price_currency_symbol - WooCommerce default
  • price_num_decimals - WooCommerce default
  • price_decimal_sep - WooCommerce default
  • price_thousand_sep - WooCommerce default
  • messages - an array of messages (see below)

The messages key contains a sub-array with the following messages used in the restaurant order form:

  • item_cannot_be_loaded - Sorry, this item cannot be loaded.
  • item_out_of_stock - Sorry, this item is out of stock.
  • item_not_available - Sorry, this item is not available.
  • error_adding_item - Sorry, there was a problem ordering this item.
  • enter_quantity_greater_than_0 - Please enter a quantity greater than 0.
  • select_all_required_options - Please select all required options.
  • address_copied - Copied!

Arguments / return
array - The script parameters.

wc_restaurant_ordering_load_frontend_scripts

Whether to load the frontend scripts and stylesheets used by the plugin. Set this to false if you have custom requirements for loading or optimizing your site's assets.

Arguments / return
bool - Whether to load the front-end scripts and styles. Default: true

wc_restaurant_ordering_menu_default_options

Filter to modify the default options for a restaurant order form. The array keys are the same as those provided to the restaurant shortcode.

Arguments / return
array - The default menu options.

wc_restaurant_ordering_menu_output

Use this filter to modify the complete restaurant order form HTML.

Arguments
string - The restaurant order form HTML.
Barn2\Plugin\WC_Restaurant_Ordering\Menu\Menu_Options - The menu options object.
WC_Product[] - The list of products displayed in this menu.

Return
string

wc_restaurant_ordering_wc_get_products_args

The arguments passed to wc_get_products to fetch the products for the order form.

Arguments / return
array - The arguments passed to wc_get_products

wc_restaurant_ordering_menu_products

Use this filter to modify the products used in a restaurant order form. See also wc_restaurant_ordering_wc_get_products_args.

Arguments
WC_Product[] - The list of products to display in this order form.
Barn2\Plugin\WC_Restaurant_Ordering\Menu\Menu_Options - The menu options object.

Return
WC_Product[]

wc_restaurant_ordering_product_limit

The maximum number of products allowed in a restaurant order form.

Arguments / return
int - The maximum number of products. Default: 250

wc_restaurant_ordering_allowed_product_types

The product types to be included in the restaurant order form.

Arguments / return
array - The product types allowed in the order form. Default:[ 'simple', 'variable' ]

wc_restaurant_ordering_show_hidden_products

Whether to show hidden products in the restaurant order form. Hidden products are those which have a catalogue visibility set to hidden.

Arguments / return
bool - Whether to show hidden products in the order form. Default: false

wc_restaurant_ordering_category_title

Filter the title for a category in the restaurant order form.

Arguments / return
string - The category title.

wc_restaurant_ordering_category_description

Filter the description for a category in the restaurant order form.

Arguments / return
string - The category description.

wc_restaurant_ordering_category_products

Filter the list of products for a category in the restaurant order form.

Arguments / return
array - The array of WC_Product objects for the category.

wc_restaurant_ordering_menu_default_product_elements

Modifies the default product details displayed in the restaurant order form. The plugin settings and shortcode options (if used) control the display of the product image, description and buy button.

Arguments / return
array - The default product elements. Default: [ 'name', 'price' ]

wc_restaurant_ordering_use_short_description

Whether to use the product short description in the order form. If false, or if the product has no short description, the product long description is used. Set this filter to false to force the display of the long description regardless of the short description.

Arguments
bool - Whether to use the short description. Default: true
WC_Product - The current product object.

Return
bool

wc_restaurant_ordering_use_long_description

Whether to use the product long description in the order form. Only applicable if the product has no short description or if the above filter is set to false. You could set this to false to prevent the long description being used in the order form, even when there's no short description.

Arguments
bool - Whether to use the long description. Default: true
WC_Product - The current product object.

Return
bool

wc_restaurant_ordering_allow_shortcodes_in_description

Whether to allow shortcodes in the order form product description. If you set this to true, you may need to override the description (see filter below) to prevent HTML tags being stripped from the description.

Arguments
bool - Whether to allow shortcodes in the description. Default: false
WC_Product - The current product object.

Return
bool

wc_restaurant_ordering_product_description_before_formatting

The product description before any shortcodes are rendered.

Arguments
string - The product description before formatting.
WC_Product - The current product object.

Return
string

wc_restaurant_ordering_product_description_before_trim

The product description before it is processed by the trimming functions to display in the order form.

Arguments
string - The product description.
WC_Product - The current product object.

Return
string

wc_restaurant_ordering_product_description_words_per_column

An array of columns mapped to the number of words permitted for each product in the order form for that number of columns.

Arguments / return
array - The words to use for each layout option, in the form: [ number of columns => words ].

wc_restaurant_ordering_product_description_length

The maximum length of the product description (number of words). When showing the full product description, this will be set to 0. If showing a limited description, it will be the maximum number of words permitted.

Arguments
int - The product description length.
WC_Product - The current product object.
Menu_Options - The menu options.

Return
int

wc_restaurant_ordering_strip_tags_from_description

Whether to strip tags from the description. Note: if the description length is greater than 0, this will happen automatically as part of the trimming functions.

Arguments
bool - Whether to strip HTML tags from the description. Default: true
WC_Product - The current product object.

Return
bool

wc_restuarant_ordering_product_name

The name of the product displayed in the order form.

Arguments
string - The product name.
WC_Product - The current product object.

Return
string

wc_restaurant_ordering_product_description

The final product description (after trimming, shortcode removal, etc) to display in the order form.

Arguments
string - The product description.
WC_Product - The current product object.

Return
string

wc_restaurant_ordering_product_image

The URL for the product image used in the order form.

Arguments
string - The product image URL.
WC_Product - The current product object.

Return
string

wc_restaurant_ordering_product_price

The price shown for the product in the order form.

Arguments
string - The product price.
WC_Product - The current product object.

Return
string

wc_restaurant_ordering_show_price_range

The price format to use for a variable product when the product has variations with different prices. This filter applies to the restaurant order form only. Possible values are:

  • short - Show the range with a "+" after the price, e.g. $3.00+
  • true - Show the full range, e.g. $3.00 - $5.00
  • false - Show the lowest price only, e.g. $3.00

Arguments / return
bool|string - The price range format to use for variable products. Default: short

wc_restaurant_ordering_show_sale_price

Whether to show the "regular" price as well as the current sale price, when the product is on sale. This filter applies to the restaurant order form only.

Arguments / return
bool - Whether to show sale prices. Default: false (only show the sale price)

wc_restaurant_ordering_product_order_type

Filter to override the product order type when the order form is first displayed.

Arguments
string - The product order type: lightbox, quick or check.
WC_Product - The current product object.
Menu_Options - The menu options.

Return
string

wc_restaurant_ordering_product_order_type_checked

The determined order type for a product. This filter is called if the initial order type was check when the menu was initially loaded. The checked order type will be one of these two values:

  • lightbox - Use the lightbox to order this product (select options, quantity, etc).
  • quick - Add 1 of this product instantly without opening the lightbox.

Arguments
string - The checked order type: lightbox or quick.
WC_Product - The current product object.

Return
string

wc_restaurant_ordering_image_size

Override the product image size used in the restaurant order form. This filter should return an array with exactly two values, of the form: [width, height].

Arguments
array - The image size for the restaurant order form. Default: image size option on settings page (used for both width and height).
WC_Product - The current product object.

Return
array

wc_restaurant_ordering_modal_data

Filter all of the product data used to display the product lightbox.

Arguments
array - The array of modal data.
WC_Product - The current product object.

Return
array

wc_restaurant_ordering_product_is_purchasable

Set this to determine whether the product in the lightbox is purchasable. Default: $product->is_purchasable() and $product->is_in_stock() and the restaurant is currently taking orders.

Arguments
bool - is the product purchasable?
WC_Product - The product object.

Return
bool

wc_restaurant_ordering_modal_product_name

Filter the product name displayed in the product modal lightbox.

Arguments
string - The product name in the lightbox
WC_Product - The product object.

Return
string

wc_restaurant_ordering_modal_product_price

Filter the product price displayed in the product modal lightbox.

Arguments
string - The product price in the lightbox (normally inside the buy button)
WC_Product - The product object.

Return
string

wc_restaurant_ordering_product_quantity_args

Filters the quantity arguments used for the quantity picker in the modal lightbox.

Arguments
array - The product quantity args - min, max, step and value
WC_Product - The product object.

Return
array

wc_restaurant_ordering_modal_use_long_description

Whether to use the product long description in the product lightbox.

Arguments
bool - Whether to use the long description in the product lightbox. Default: true
WC_Product - The current product object.

Return
bool

wc_restaurant_ordering_modal_use_short_description

Whether to use the product short description in the product lightbox. This filter is only applicable if there is no long description for the product, or if the above filter is set to false.

Arguments
bool - Whether to use the short description in the product lightbox. Default: true
WC_Product - The current product object.

Return
bool

wc_restaurant_ordering_modal_description_before_formatting

Filter the product description displayed in the lightbox before any formatting is applied. This is run before the_content filters are applied, so before any shortcodes are proccessed.

Arguments
string - The product description before formatting.
WC_Product - The product object.

Return
string

wc_restaurant_ordering_modal_description

Filter the product description displayed in the lightbox after the_content filters are applied.

Arguments
string - The formatted product description.
WC_Product - The product object.

Return
string

wc_restaurant_ordering_modal_image

Filter the product image URL for the image in the lightbox.

Arguments
string - The product modal image URL.
WC_Product - The current product object.

Return
string

wc_restaurant_ordering_modal_image_size

Set the product image size used in the product lightbox. Expects an array with exactly two elements, of the form: [width, height].

Arguments
array - The lightbox image size. Default: [500, 300]
WC_Product - The current product object.

Return
array

wc_restaurant_ordering_modal_stock_status

Filters the product stock status in the lightbox.

Arguments
string - The stock status.
WC_Product - The product object.

Return
string

wc_restaurant_ordering_modal_cache_time

The product lightbox is cached to improve load times. Use this filter to adjust to the cache time or set it to 0 to remove caching altogether.

Arguments / return
int - The cache time in seconds. Default: 1800 (30 minutes)

wc_restaurant_ordering_modal_cache_time_adjusted

The cache time (in seconds) when the next restaurant open or close time is within the next 60 minutes. The cache time is reduced in this case to prevent incorrect data being shown to customers.

Arguments / return
int - The adjusted cache time in seconds. Default: various values depending how close the next open or close time is.

wc_restaurant_ordering_show_cart_notice

Whether to show the cart notice at the top of the page, after a product is successfully added to the cart. Using this filter will override the 'Show cart confirmation' option on the settings page.

Arguments / return
bool - Whether to show the cart notice. Default: true

wc_restaurat_ordering_cart_message_include_quantities

Whether to display the quantity added in the cart notice displayed after a product is added to the cart.

Arguments / return
bool - Whether to include quantities in the "add to cart" notice. Default: true

wc_restaurat_ordering_cart_message_product_name_in_quotes

Whether to display the product name in quotes in the cart notice displayed after a product is added to the cart.

Arguments / return
bool - Whether to display the product name in quotes in the "add to cart" notice. Default: true

wc_restaurant_ordering_show_all_cart_errors

Whether to show all cart errors when adding to the cart, if there is more than one error found.

Arguments / return
bool - Whether to show all cart errors. Default: false

wc_restaurant_ordering_refresh_cart_fragments

Whether to refresh the 'cart fragments' after a product is added to the cart. The value of this hook is passed to the plugin's javascript. If true an event is triggered when a product is added to the cart. Most themes respond to this event and update any cart elements on the page (e.g. cart widgets in the sidebar or cart icons in the header).

Arguments / return
bool - Whether to refresh the cart fragments. Default: true

wc_restaurant_ordering_rest_validate_cart_params

Filter the validated parameters during the REST request to add the product to the cart.

Arguments
array - The product parameters after validation (array keys are: product_id, product, quantity, variations, and variation_id).
WC_Product - The current product object.

Return
array

wc_restaurant_ordering_handle_cart_validation

Whether to handle cart validation during checkout. If true the plugin will check the contents of the cart, and if any "restaurant" products are found, it will then check the open/close state of the restaurant.

Set this filter to false to prevent any cart validation during checkout.

Arguments / return
bool - Whether to validate the cart on checkout. Default: true

wc_restaurant_ordering_navigation_minimum_categories_to_display

Filter the minimum number of categories required for the menu navigation to display.

Arguments / return
int - The minimum number of categories. Default: 2

wc_restaurant_ordering_is_restaurant_open

Use this filter to decide whether the restaurant is open or closed. The default value is based on the restaurant opening hours and the current time of day. Use this filter to manually override the open/close state.

Arguments / return
bool - Whether the restaurant is currently open.

wc_restaurant_ordering_allow_orders_when_closed

Whether to allow orders when the restaurant is closed. By default, if the restaurant is closed, the user will be prevented from placing an order, and an error message will be shown on checkout. Use this filter to allow orders when the restaurant is closed.

Arguments / return
bool - Whether to allow orders when closed. Default: false

wc_restaurant_ordering_default_availability_options

Filter the default availability options object used by the plugin. The default object will contain the options set on the settings page, so use this filter if you want to modify the availability settings (e.g. open notice, closed notice) in certain parts of your site, without modifying the central plugin settings.

Arguments / return
Barn2\Plugin\WC_Restaurant_Ordering\Info\Availability_Options - The availability options object.

wc_restaurant_ordering_availability_closed_error

Filters the message shown on the checkout and product lightbox when the restaurant is closed.

Arguments / return
string - The error message. Default: Sorry, the restaurant is now closed.

wc_restaurant_ordering_availability_open_notice

Filters the message shown above the order form when the restaurant is open.

Arguments / return
string - The availability message. Default: option on settings page.

wc_restaurant_ordering_availability_closed_notice

Filters the message shown above the order form when the restaurant is closed.

Arguments / return
string - The availability message. Default: option on settings page.

wc_restaurant_ordering_info_show_availability_notice

Whether to show the availability notice above the order form. This is the open or closed message, depending on the current restaurant state.

Arguments / return
bool - Whether to show the availability notice. Default: true if opening hours are defined on the settings page.

wc_restaurant_ordering_availability_text_replacements

The text replacements to apply to the open or close time messages. The supported tags are {open_time} and {close_time}. Use this filter to add extra tags.

Arguments
array - The text replacements. Each key should correspond to a tag you want to replace without the curly brackets. The default keys are 'open_time' and 'close_time'.
Barn2\Plugin\WC_Restaurant_Ordering\Info\Opening_Hours - The current restaurant opening hours.
Barn2\Plugin\WC_Restaurant_Ordering\Info\Availability_Options - The availability options object.

Return
array

wc_restaurant_ordering_availability_open_time_include_day

If the restaurant is closed, this filter sets whether to include the day of the week in the next opening time for the restaurant.

Arguments / return
bool - Whether to include the day in the next opening time. Default: true

wc_restaurant_ordering_opening_hours_time_with_day_format

Sets the format for the next opening time when the day of the week is included. Expects a PHP date/time format string.

Arguments / return
string - The date/time format. Default: the WordPress time format with , l appended, e.g. g:ia, l.

wc_restaurant_ordering_opening_hours_time_format

Sets the format for open and close times displayed in the plugin. Expects a PHP time format string.

Arguments / return
string - The time format. Default: the WordPress time format (General -> Settings).

wc_restaurant_ordering_opening_hours_start_week_on_sunday

By default, the opening hours start on Monday. Use this filter to start the week on a Sunday. This will affect the display of the opening hours in the 'More' box above the restaurant order form.

Arguments / return
bool - Whether to start the week on a Sunday. Default: false

wc_restaurant_ordering_opening_hours_days_of_week

The days of the week to use for the restaurant opening hours. Use this filter to remove specific days if you don't want them to appear.

Arguments / return
array - The days of the week to use. Default: [ 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday' ]

wc_restaurant_ordering_timezone

The timezone (DateTimeZone object) to use for open and close time calculations for the restaurant. This is used when determining the status of the restaurant for the current user.

Arguments / return
DateTimeZone - the timezone object. Default: wp_timezone()

wc_restaurant_ordering_default_information_options

Filter the default information options object used by the plugin. The default object will contain the options set on the settings page, so use this filter if you want to modify the information settings (e.g. restaurant name, address, etc) in certain parts of your site, without modifying the central plugin settings.

Arguments / return
Barn2\Plugin\WC_Restaurant_Ordering\Info\Information_Options - The information options object.

wc_restaurant_ordering_info_restaurant_name

Filters the restaurant name shown above the order form.

Arguments / return
string - The restaurant name. Default: option on settings page.

wc_restaurant_ordering_info_restaurant_address

Filters the restaurant address shown above the order form.

Arguments / return
string - The address. Default: option on settings page.

wc_restaurant_ordering_info_delivery_notice

Filters the delivery notice shown above the order form when the restaurant is open.

Arguments / return
string - The delivery notice. Default: option on settings page.

wc_restaurant_ordering_info_show_delivery_notice

Whether to show the delivery notice above the order form.

Arguments / return
bool - Whether to show the delivery notice. Default: true if restaurant is open, false otherwise.

Whether to show the "More" link above the order form, to show the restaurant information and opening times.

Arguments / return
bool - Whether to show the "More" link notice. Default: true if opening hours are set.

wc_restaurant_ordering_override_woocommerce_shop_page

Whether to override the WooCommerce Shop page with the restaurant order form. This filter only applies on the Shop page and when no product search is applied.

It allows you to override the default behavior of the plugin, which is to display the shop page only when the Restaurant Order page is set to the main shop page, and the shop display option is set to 'Products' or 'Products and Categories'.

Arguments / return
bool - Whether to display the restaurant order form on the Shop page.

wc_restaurant_ordering_woocommerce_shop_page_options

Filter the list of order form options (i.e. the shortcode options) used when the restaurant order form is displayed on the Shop page.

Arguments / return
array - The array of shortcode options. Default: options on settings page.

wc_restaurant_ordering_override_woocommerce_category_page

Whether to override the WooCommerce category pages with the restaurant order form. This filter only applies on category archive pages.

Arguments / return
bool - Whether to display the restaurant order form on WooCommerce category pages. Default: option on settings page.

wc_restaurant_ordering_woocommerce_category_page_options

Filter the list of order form options (i.e. the shortcode options) used when the restaurant order form is displayed on a WooCommerce category page.

Arguments / return
array - The array of shortcode options. Default: options on settings page, except categories which is set to the current category, and restaurant_info which is set to false.

Actions

wc_restaurant_ordering_load_scripts

Fired immediately after the scripts and styles for the plugin have been queued.

wc_restaurant_ordering_before_menu

Fired in the main restaurant order form template, before the restaurant menu is displayed.

wc_restaurant_ordering_before_restaurant_info

Fired in the main restaurant order form template, before the restaurant information is displayed.

wc_restaurant_ordering_before_menu_navigation

Fired in the main restaurant order form template, before the menu category navigation is displayed.

wc_restaurant_ordering_before_menu_items

Fired in the main restaurant order form template, just before the list of food items (products) are displayed.

wc_restaurant_ordering_after_menu_items

Fired in the main restaurant order form template, just after the list of food items (products) are displayed.

wc_restaurant_ordering_after_menu

Fired in the main restaurant order form template, just after the restaurant menu is displayed.

wc_restaurant_ordering_before_menu_section

Fired in the restaurant order form category template, before the HTML for the category section (including title and products) is displayed.

wc_restaurant_ordering_after_menu_section

Fired in the restaurant order form category template, after the HTML for the category section (including title and products) is displayed.

wc_restaurant_ordering_before_menu_section_title

Fired in the restaurant order form category template, before the category title and description are displayed.

wc_restaurant_ordering_before_menu_section_description

Fired in the restaurant order form category template, before the category description is displayed.

wc_restaurant_ordering_after_menu_section_title

Fired in the restaurant order form category template, after the category title and description are displayed.

wc_restaurant_ordering_before_menu_section_products

Fired in the restaurant order form category template, before the HTML for the products for this category are displayed.

wc_restaurant_ordering_after_menu_section_products

Fired in the restaurant order form category template, after the HTML for the products for this category are displayed.

wc_restaurant_ordering_before_menu_product

Fired in the restaurant order form product template, before the product is displayed.

wc_restaurant_ordering_after_menu_product

Fired in the restaurant order form product template, after the product is displayed.

wc_restaurant_ordering_before_add_to_cart

Fired during the 'add to cart' action, just before the call to WC()->cart->add_to_cart(). Use this hook if you need to do some custom add to cart logic for a specific product .

Arguments
array - The list of cart params - product_id, quantity, variation_id and variations

wc_restaurant_ordering_after_add_to_cart

Fired during the 'add to cart' action, just after the call to WC()->cart->add_to_cart(). Use this hook if you need to do some custom add to cart logic for a specific product .

Arguments
array - The list of cart params - product_id, quantity, variation_id and variations

Related Articles

If searching the knowledge base hasn't answered your question, please contact support.