How to restrict coupons to WooCommerce custom taxonomies

Smart Coupons provide a powerful, “all-in-one” solution for gift cards, store credits, discount coupons, and vouchers extending the core functionality of WooCommerce coupons.

If you want to exclude all your popular subscription products from coupon discounts, or include discounts on all products sharing the common tag and other product-related use cases, the coupon taxonomy restriction feature can help you achieve it.

In this document, you can find ways to restrict coupons to the custom taxonomies that you have created.

How to create custom taxonomies

↑ Back to top

To create a custom taxonomy such as Material, Warranty, Occasion, or Style, you can find plugins that are available on the wordpress.org/plugins page that is available by searching with “woocommerce custom taxonomy”.

A free plugin that can be used to create custom taxonomies is https://wordpress.org/plugins/custom-post-type-ui/

If you are familiar with custom codes, you can utilize the code available below:

// Register 'Collection' Custom Taxonomy for WooCommerce Products
function register_product_collection_taxonomy() {
    $labels = array(
        'name'              => _x( 'Collections', 'taxonomy general name', 'textdomain' ),
        'singular_name'     => _x( 'Collection', 'taxonomy singular name', 'textdomain' ),
        'search_items'      => __( 'Search Collections', 'textdomain' ),
        'all_items'         => __( 'All Collections', 'textdomain' ),
        'parent_item'       => __( 'Parent Collection', 'textdomain' ),
        'parent_item_colon' => __( 'Parent Collection:', 'textdomain' ),
        'edit_item'         => __( 'Edit Collection', 'textdomain' ),
        'update_item'       => __( 'Update Collection', 'textdomain' ),
        'add_new_item'      => __( 'Add New Collection', 'textdomain' ),
        'new_item_name'     => __( 'New Collection Name', 'textdomain' ),
        'menu_name'         => __( 'Collections', 'textdomain' ),
    );

    $args = array(
        'hierarchical'      => true, // Like categories
        'labels'            => $labels,
        'show_ui'           => true,
        'show_admin_column' => true,
        'rewrite'           => array( 'slug' => 'collection' ),
        'show_in_rest'      => true, // To make it visible in Gutenberg and REST API
    );

    register_taxonomy( 'product_collection', array( 'product' ), $args );
}
add_action( 'init', 'register_product_collection_taxonomy' );

To know more about the above snippet, you can check the WordPress documentation here. To safely add code snippets, you can follow the documentation here.

How to restrict custom taxonomies with Smart Coupons

↑ Back to top

To restrict coupons to custom taxonomies, follow the steps below: 

  1. Navigate to Marketing > Coupons.
  2. Create a new coupon or edit an existing coupon.
  3. Navigate to “Usage restriction tab > Smart Coupon Restrictions:” Select “Taxonomy” from the dropdown and click on the “+” symbol.
  4. In the Taxonomy dropdown, you can find the custom taxonomy you created. In our case it is “Collections“. 
  5. Update the coupon.

That’s it!