Product Attributes Shortcode

Description

Provides a shortcode to display a linked list of terms from a product attribute, such as all brand links from a brands attribute.

Features

  • Displays a list of all terms from a specific product attribute
  • Choose if these links filter products or go to term archives
  • List of terms does not reduce as products are filtered
  • Various shortcode attributes to modify the display

Usage

Use the following shortcode replacing the x with your attribute name:

[wcpas_product_attributes attribute="x"]

If your attribute has spaces in the name then replace these with hyphens in the shortcode, if you have other characters in your attribute name see the related FAQ below.

There are various other shortcode attributes which can be used, if these are omitted the defaults are used, the available shortcode attributes are:

  • archive_links1 to enable archive links e.g. /brand/sega/, 0 to disable e.g. /shop/?filter_brand=sega, default is 0
  • current_attribute_link1 to still display a link if the current page, 0 to disable, default is 1
  • hide_empty1 to hide empty terms, 0 to disable, default is 1
  • links_target – Use a HTML link target e.g. _blank to open links in a new window, default is empty
  • min_price – Use a minimum price number for links to include a minimum price filter, requires archive_links="0", default is empty
  • max_price – Use a maximum price number for links to include a maximum price filter, requires archive_links="0", default is empty
  • orderasc or desc, default is asc
  • orderby – Any orderby parameter, default is name
  • show_counts1 to enable display of term counts, 0 to disable, default is 0
  • show_descriptions1 to enable display of term descriptions, 0 to disable, default is 0

Example shortcode using multiple shortcode attributes:

[wcpas_product_attributes attribute="brand" archive_links="0" current_attribute_link="0" hide_empty="0" links_target="_blank" min_price="50.00" max_price="500.00" order="desc" orderby="id" show_counts="1" show_descriptions="1"]

Screenshots

  • Shortcode display
  • Shortcode added via block

Installation

Minimum Requirements

  • PHP 7.3.0
  • WooCommerce 7.9.0
  • WordPress 6.1.0

Installing

You can install Product Attributes Shortcode via:

  • Automatic installation
  • Manual installation with FTP client
  • WordPress dashboard upload

More information

Screen Sizes

  • Frontend: Where elements may be displayed on the frontend they will fit within the screen width
  • Backend: Where interfaces may be displayed it is recommended to use a desktop computer with a resolution of 1920×1080 or higher. For lower resolutions any interfaces will attempt to fit within the screen width but some elements may be close together and/or larger than the screen width

FAQ

Nothing is displaying?

Ensure you have included the shortcode correctly and that the attribute you are using has products assigned. If nothing is still displaying the attribute name you have entered may not be in the correct format, see the related FAQ for more information.

What attribute name/format do I use?

If your attribute is a single word you just need to enter that. If your attribute has spaces in the name, replace these with hyphens in the shortcode attribute. For more complex attribute names e.g. with special characters you can determine what the attribute name is by editing the attribute in Products > Attributes, in the URL you will see something like /edit-tags.php?taxonomy=pa_example-attribute&post_type=product, the part after the pa_ and before the & is your attribute name, in this example it is example-attribute.

Why aren’t my list of terms linked?

The list will not include links on the terms if you are using archive_links="1" and the attribute used does not have archives enabled on the attribute which is set when editing the attribute in Products > Attributes .

My terms are linked but the links do not work?

Links are filter based which use your shop page (unless you are using archive_links="1"), if they are not working you may have not configured a shop page in WooCommerce, this is created during installation of WooCommerce, if it has been removed it will need recreating.

Minimum/maximum price is not working?

These are filter based and therefore require archive_links="0".

Can I use it in a page, post, widget, block, etc?

You can use it anywhere you can use a shortcode.

Can I use it in a PHP template?

Yes, use the do_shortcode function of WordPress to echo the shortcode.

How do I style it?

You will need to apply some custom CSS styling, each shortcode used outputs a <ul> element containing <li> elements for each term. Elements including and within the <ul> have classes and IDs for custom CSS styling purposes.

Reviews

Read all 2 reviews

Contributors & Developers

“Product Attributes Shortcode” is open source software. The following people have contributed to this plugin.

Contributors

Changelog

1.9.0 – 2024-01-16

  • Add: WooCommerce Cart/Checkout blocks compatibility
  • Update: Changelog consistency

1.8.0 – 2023-12-18

  • Add: current_attribute_link shortcode attribute
  • Add: Class of wcpas-product-attribute-current to current attribute li element
  • Update: Changelog keys
  • Update: Code consistency
  • Update: Development assets
  • Update: PHP requires at least 7.3.0
  • Update: WooCommerce requires at least 7.9.0
  • Update: WooCommerce tested up to 8.4.0
  • Update: WordPress requires at least 6.1.0
  • Update: WordPress tested up to 6.4.2

1.7.0 – 2023-09-19

  • Add: links_target shortcode attribute
  • Add: show_descriptions shortcode attribute
  • Add: Additional classes/IDs to markup for targeted custom CSS styling purposes
  • Update: WooCommerce tested up to 8.1.1
  • Update: WordPress tested up to 6.3.1

1.6.0 – 2023-08-02

  • Add: High Performance Order Storage (HPOS) compatibility if WooCommerce version is 8.0.0 or higher, note that this version includes several changes for HPOS compatibility, it is recommended you perform this upgrade on a staging environment before upgrading the extension on a production website regardless of whether HPOS enabled, HPOS and the compatibility in this extension are very new, use with caution
  • Update: Development assets
  • Update: PHP requires at least 7.2.0
  • Update: WooCommerce requires at least 7.3.0
  • Update: WooCommerce tested up to 7.9.0
  • Update: WordPress requires at least 5.9.0
  • Update: WordPress tested up to 6.2.2

1.5.0 – 2022-10-22

  • Add: If attribute is not entered lower case it will still display the list
  • Update: Filter links now use add_query_arg
  • Update: Code refactoring
  • Update: PHP requires at least 7.0.0
  • Update: WooCommerce requires at least 5.0.0
  • Update: WordPress requires at least 5.4.0
  • Update: WordPress tested up to 6.0.3

1.4.0 – 2022-04-23

  • Add: Escaping of URLs, attributes and overall attributes list markup
  • Update: WordPress tested up to 5.9.3

1.3.0 – 2022-03-25

  • Add: wcpas_product_attributes_translation function
  • Add: WooCommerce not installed/activated notice
  • Update: WordPress tested up to 5.9.2
  • Fix: Translations may not load due to load_plugin_textdomain not hooked on init

1.2.0 – 2021-07-16

  • Add: min_price shortcode attribute (archive_links must be false to use)
  • Add: max_price shortcode attribute (archive_links must be false to use)

1.1.0 – 2021-05-12

  • Add: archive_links shortcode attribute
  • Update: Default link used is a filter based term link

1.0.0 – 2021-05-11

  • New: Initial release