Support » Plugin: WooCommerce » Add Coupon Exclusion By Attribute

  • Resolved OC WordPress Web Designer

    (@oc-wordpress-web-designer)



    The coupon exclusion rules only apply to product categories and individual products. Can you apply an exclusion rule by attribute? I want to have a coupon that excludes a color.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Justin Shreve

    (@jshreve)

    You can’t exclude just an attribute. However, if you configure your products as variable products (https://docs.woocommerce.com/document/variable-product/) based on those attributes, you can exclude specific variations (say a red version of a t-shirt) from a coupon just like you would a normal product.

    OC WordPress Web Designer

    (@oc-wordpress-web-designer)

    All my products are variable products, but I have ALOT of variations so there are like 10 different priced variations with the color black for each product.

    https://beachcandyswimwear.com/shop/swimwear/triangle-bikini-top/?attribute_pa_color=olive&attribute_pa_candy=no-candy&attribute_pa_pads=no-pads

    I was hoping to duplicate the coupon category exclude and switch for attributes in the class-wc-meta-box-coupon-data.php.

    Is that possible?

    // Exclude Categories
    ?>
    <p class=”form-field”><label for=”exclude_product_categories”><?php _e( ‘Exclude categories’, ‘woocommerce’ ); ?></label>
    <select id=”exclude_product_categories” name=”exclude_product_categories[]” style=”width: 50%;” class=”wc-enhanced-select” multiple=”multiple” data-placeholder=”<?php esc_attr_e( ‘No categories’, ‘woocommerce’ ); ?>”>
    <?php
    $category_ids = $coupon->get_excluded_product_categories();
    $categories = get_terms( ‘product_cat’, ‘orderby=name&hide_empty=0’ );

    if ( $categories ) {
    foreach ( $categories as $cat ) {
    echo ‘<option value=”‘ . esc_attr( $cat->term_id ) . ‘”‘ . selected( in_array( $cat->term_id, $category_ids ), true, false ) . ‘>’ . esc_html( $cat->name ) . ‘</option>’;
    }
    }
    ?>
    </select> <?php echo wc_help_tip( __( ‘Product categories that the coupon will not be applied to, or that cannot be in the cart in order for the “Fixed cart discount” to be applied.’, ‘woocommerce’ ) ); ?></p>
    <?php

    echo ‘</div><div class=”options_group”>’;

    ——

    Then add below to class-wc-coupon.php but for the attributes created above.

    // Exclude Categories
    ?>
    <p class=”form-field”><label for=”exclude_product_categories”><?php _e( ‘Exclude categories’, ‘woocommerce’ ); ?></label>
    <select id=”exclude_product_categories” name=”exclude_product_categories[]” style=”width: 50%;” class=”wc-enhanced-select” multiple=”multiple” data-placeholder=”<?php esc_attr_e( ‘No categories’, ‘woocommerce’ ); ?>”>
    <?php
    $category_ids = $coupon->get_excluded_product_categories();
    $categories = get_terms( ‘product_cat’, ‘orderby=name&hide_empty=0’ );

    if ( $categories ) {
    foreach ( $categories as $cat ) {
    echo ‘<option value=”‘ . esc_attr( $cat->term_id ) . ‘”‘ . selected( in_array( $cat->term_id, $category_ids ), true, false ) . ‘>’ . esc_html( $cat->name ) . ‘</option>’;
    }
    }
    ?>
    </select> <?php echo wc_help_tip( __( ‘Product categories that the coupon will not be applied to, or that cannot be in the cart in order for the “Fixed cart discount” to be applied.’, ‘woocommerce’ ) ); ?></p>
    <?php

    echo ‘</div><div class=”options_group”>’;

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Add Coupon Exclusion By Attribute’ is closed to new replies.