Last Modified: KB » [if] Shortcode Pro
WooCommerce Compatibility

The [if /] Shortcode offers WooCommerce compatibility as well. This is achieved through special Shortcode Attributes that are designed to work exclusively with the WooCommerce plugin for WordPress. Below is a list of Shortcode Attributes that are compatible with WooCommerce.

Attributes that Require WooCommerce

All WooCommerce-Compatible Attributes

WooCommerce Restrictions (s2X)

We also offer a plugin called WooCommerce Restrictions (s2X). If you have this plugin, you can check a Customer's access to any given 'Restriction' in WooCommerce using current_user_can="{capability|expr}"

Example 1

In this example, I am checking a WooCommerce 'Restriction' that has a Slug of elite. I can check if the current User can access content that is protected by that Restriction using a special prefix: access_pkg_, followed by the Restriction Slug. It's worth noting that in the WooCommerce Restrictions plugin, you can create any number of Restrictions and give each Restriction a custom Slug. See also: Creating A Restriction

[if current_user_can="access_pkg_elite"]
    You can access the Elite Restriction package on a site running WooCommerce Restrictions.
    [else]
        Access denied.
[/if]

Example 2

The current_user_can="{capability|expr}" Attribute also supports Simple Expressions. You can use this Attribute to check multiple Capabilities using logical operators such as AND, OR. In the following example, the OR operator is used to check if the current User can access the Elite Restriction package, OR has the ability to edit_posts. Users who can edit_posts might include Administrators, Editors, Authors, Contributors, etc.

[if current_user_can="access_pkg_elite OR edit_posts"]
    You can access the Elite Restriction package on a site running WooCommerce Restrictions, or you can edit Posts in WordPress.
    [else]
        Access denied.
[/if]

See also: WordPress Roles/Capabilities