Product_Data

Functions for retrieving data for a product in the restaurant menu.

Tags
author

Barn2 Plugins support@barn2.com

license

GPL-3.0

copyright

Barn2 Media Ltd

Table of Contents

get_display_price()  : string
Get the display price for a product. Similar to WC_Product->get_price_html() but without any price suffix.
get_image_url()  : string
Get the image URL for a product. Similar to WC_Product->get_image() but returns the URL rather than the full <img> tag.
get_order_type()  : string
Get the supported order type for a product. Variable products always return 'lightbox'.
get_quantity_args()  : array<string|int, mixed>
Get the quantity args for a product. The args include the quantity value as well as its min, max and step.

Methods

get_display_price()

Get the display price for a product. Similar to WC_Product->get_price_html() but without any price suffix.

public static get_display_price(WC_Product $product[, bool|string $show_range = true ][, bool $show_sale_price = false ]) : string
Parameters
$product : WC_Product

The product object.

$show_range : bool|string = true

Applies to variable products only. Whether to show the range of prices (e.g. £2.00 - £4.00). true - show full price range for variable products; false - show minimum price only; 'short' - show minimum price appended with "+".

$show_sale_price : bool = false

Applies if product is on sale. true - show the regular price struck out before the sale price; false - just show the sale price.

Return values
string

The display price.

get_image_url()

Get the image URL for a product. Similar to WC_Product->get_image() but returns the URL rather than the full <img> tag.

public static get_image_url(WC_Product $product[, string $image_size = 'woocommerce_single' ]) : string
Parameters
$product : WC_Product

The product object.

$image_size : string = 'woocommerce_single'

The image size to retrieve.

Return values
string

The image URL, or an empty string if product has no image.

get_order_type()

Get the supported order type for a product. Variable products always return 'lightbox'.

public static get_order_type(WC_Product $product) : string
Parameters
$product : WC_Product

The product object.

Return values
string

The supported order type ('lightbox' or 'quick').

get_quantity_args()

Get the quantity args for a product. The args include the quantity value as well as its min, max and step.

public static get_quantity_args(WC_Product $product) : array<string|int, mixed>

The args are run through the 'woocommerce_quantity_input_args' filter to allow quantity plugins to override.

Parameters
$product : WC_Product

The product object

Return values
array<string|int, mixed>

The quantity args - an array with 'value', 'min', 'max' and 'step' keys

Search results