perch_shop_product_variants()
Display a list of product variants for a given product with perch_shop_product_variants().
Requires
- Perch Shop installed
Parameters
| Type | Description |
|---|---|
| String | Slug of the product to show variants for |
| Array | Options array, see table below |
| Boolean | Set to true to have the value returned instead of echoed. |
Options array
| Name | Value |
|---|---|
| template | The name of a template to use to display the content. |
| sort | The ID of the field to sort on. |
| sort-order | Either ASC (ascending), DESC (descending) or RAND (random). |
| sort-type | Either alpha or numeric. Default is alpha. |
| count | The number of items to display. |
| start | The item number to start displaying from. |
| filter | The ID of a field to filter the results by. |
| match | Used with filter, see the below table for values |
| value | Used with filter and match. The value to match. For between and in, takes a comma delimited string. For regex takes PCRE regular expression. |
| category | Filter by one or more categories. See Category filtering |
| category-match | Either any or all. See Category filtering |
| skip-template | True or false. Bypass template processing and return the content in an associative array. |
| return-html | True or false. For use with skip-template. Adds the HTML onto the end of the returned array with key html. |
| split-items | True or false. Return an array of individually templated items. |
| raw | True or false. Returns unprocessed content, for use alongside skip-template. |
| paginate | True or false. Whether to use pagination. |
| count | Integer. (When used with paginate) The number of items to show per page if pagination is being used. |
| pagination-var | The URL query string parameter name to use for the page number. Defaults to page. |
| page-links | True or false. Create numbered page links as well as previous and next links. |
| page-link-template | The template to use (if not the default) to generate the page links. |
| page-link-style | shortened or all. By default a shortened set of page links are generated. If you want a link for every page, set to all. |
Usage examples
Display the products using the default template which is shop/products/list.html.
perch_shop_product_variants('my-product');
This function accepts an array of options to control what is returned. It can be used as follows.
perch_shop_product_variants('my-product', [
'template' => 'products/custom-listing.html',
]);