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

Javascript API

This article documents the Javascript API for WooCommerce Restaurant Ordering. This article is aimed at developers.

window.wcRestaurantMenu

The wcRestaurantMenu object provides the following functions:

init

Initializes all restaurant order forms on the current page.

addRemoveProduct

Adds a product to the cart. Note: despite the name of this function, it can only be used to add products, not remove them.

Arguments
int - The product ID.
float - The quantity to add or remove.

Return
jqXHR - The jQuery XHR object for the add to cart request.

checkOrderType

Checks the supported order type for a product.

Arguments
int - The product ID to check.

Return
jqXHR - The jQuery XHR object for the order type request.

showCartNotice

Show a cart notice at the top of the screen. This is used in conjunction with the cart-notice.php template. See the article on templates for more details.

Arguments
object - The cart notice data with the following properties:

  • success:bool (required) - to indicate if it's a success or error notice.
  • error_message: string (optional) - the error message if this is an error notice.

int - The cart notice timeout in milliseconds.

window.wcRestaurantProductModal

The wcRestaurantProductModal object provides the following functions:

load

Loads a lightbox for a product from the database.

Arguments
int - The product ID to load.

Return
jqXHR - The jQuery XHR object for the modal load request.

show

Shows a lightbox for a product based on supplied product data.

Arguments
object - The product data.

close

Closes the current lightbox.

getCurrentModal

Retrieve the current modal object.

Return - a Modal object.

getModalElement

Retrieve the main element for the product lightbox.

Return - jQuery object of the current modal.

setPrice

Sets the base price for the for the product in the lightbox, to be added to the order. This data passed to this function is stored as data against the product and is used to calculate the total price for this item.

Arguments
float - The base price for the product. This is multiplied by the quantity to add to calculate the total price.

setExtras

Sets the price for the 'extras' (e.g. extra toppings) for the product in the lightbox, to be added to the order. This data passed to this function is stored as data against the product and is used to calculate the total price for this item.

Arguments
float - The total amount of any extras to add to the price.

Events

wro:modal:load

This event is triggered when the data for a product modal is loaded from the restaurant menu. This occurs before wro:modal:open and wro:modal:init. Event data:

  • response - the response object. Contains the following properties:
      • success - Whether the modal request was successful.
      • product_data - The product data used to populate the modal.

wro:modal:init

Triggered when the product modal has been initialized (events have been bound, etc). This

wro:modal:open

Triggered when a product modal is opened.

wro:modal:close

Triggered when a product modal is closed.

wro:modal:update_price

Triggered when the total price for the current product in the modal hass changed (e.g. when the user updates the quantity or selects a variation).

wro:modal:change_quantity

Triggered when the quantity in the product modal is changed.

wro:modal:add_quantity

Triggered when the quantity in the product modal is increased.

wro:modal:remove_quantity

Triggered when the quantity in the product modal is decreased.

wro:modal:before_add_product

Triggered just before the REST request to add the selected product in the current modal to the cart. Event data:

  • formData - The form data to be submitted.

wro:modal:add_product

Triggered on successful addition of a product to the cart from the modal. See wro:add_product for the event data.

wro:modal:add_product_complete

Triggered when the REST request to add a product to the cart from the modal has completed (on success or failure).

wro:modal:add_product_fail

Triggered if there was an error adding to the cart from the product modal.

wro:before_add_product

Triggered just before the REST request to add a product to the cart from the order form. Event data is an object containing product_id and quantity.

wro:add_product

Triggered when a product is adde to the cart, either from the menu order form or the product modal. Event data:

  • response – the cart response object. This contains the following properties:
    • products – The list of products added.
    • num_products_added - The total number of products.
    • quantity_added - The quantity added.
    • product_name – The product name.
    • fragments – The cart “fragments” used by WooCommerce. Usually just contains the mini-cart widget.
    • cart_hash – An encoded hash of the cart. This is used by WooCommerce when triggering cart events.

wro:add_product_complete

Triggered when the REST request to add a product to the cart from the order form has completed (on success or failure).

wro:add_product_fail

Triggered if there was an error adding to the cart.

Related Articles

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