Are you looking for ways to use discount codes more efficiently? I have something for you. This guide provides various ways to exclude woocommerce products from coupons to avoid discounts. Now, with the advent of Black Friday and Christmas, many online stores are offering transactions and promotions. When setting up discount coupons and sharing them online, ensure that the revenue will not decrease significantly. If the sales increase by 25%, but the sales profit decreases by 50%, it is best not to offer a discount. Finding the right balance between more sales and the profit of each sales unit is not always easy. One of the best ways to do this is to keep certain products non discounted. You can use specific discount items (such as hook up) and then try to sell additional products without discount to the customer.
This guide provides a variety of ways to exclude woocommerce products from coupons to avoid discounts. Why exclude products from coupons? The use of discount coupons is a general marketing strategy used by woocommerce stores to increase sales. If used wisely, discounts may help online business. However, if it is not applied correctly, sales growth does not mean price decline, and revenue will also decrease. If the directory is larger, customers may encounter vulnerabilities. For example, you may not want to apply a discount to a bundle that already has a discount applied. Similarly, if customers apply discounts to products with already low profits, they may eventually lose money.
Therefore, it is recommended to exclude specific woocommerce products from discount coupons. This allows you to generate the required discount coupons and codes without affecting a particular product. Let’s take a look at how to do this and the kinds of tools that can be used to exclude products from discounts. There are two main ways to exclude woocommerce products from Coupons: exclude woocommerce products from discount coupons. Let’s look at each option in detail programmatically using the default woocommerce option. 1) Use the default woocommerce option, except for woocommerce products in coupons, which provides the option to disable specific coupons for specific products and categories. To access these options, go to woocommerce > coupons from the WordPress administrator dashboard.
Then, under coupons, click Edit to open the coupon you want to exclude. Then scroll down to the restricted use tab. Here, you can use the \
When there are many coupons, you need to add a product you want to exclude, so it may take a lot of time in this process. The good news is that some code has more efficient methods. Let’s look at how to programmatically exclude woocommerce products from all coupons. 2) You can also programmatically exclude woocommerce products from coupons and woocommerce products from discount coupons. The advantage of this method is that it provides great flexibility and can avoid discounts for specific items. For example, to disable a specific product ID for a coupon or add a check box to the woocommerce product data option,
。
Let’s see how to activate some of these options. Note: you will edit some key files, so it is recommended to create a backup of the site before you start, and if not, install the sub theme. 2.1) one of the easiest ways to exclude woocommerce products from coupons using product IDS is to add code snippets to ensure that coupons with specific product IDS do not work. To do this, you must first find the product ID. To do this, when you open the WordPress administrator dashboard and navigate to the product, a list of all wordcom products will be displayed. If you move the mouse over a product for which you do not want to apply a discount, the product ID is displayed.
If you need it in the next step, please write it down. Then navigate to shape > Theme Editor and open the theme feature file. Then use the correct theme file sidebar and use functions. Open the PHP file. Male add the following code snippet to the file, but don’t forget to replace it with the corresponding ID of the product_id you want to exclude. add_filter( ‘woocommerce_coupon_is_valid_for_product’, ‘quadlayers_exclude_product_from_product_promotions’, 9999, 4 );
Functions quadlayers_exclude_product_from_product_productions ($valid, $product, $coupon, $values){
\/\/Replace product ID (e.g. 145)
if ( PRODUCT_ID == $product->get_id() ) {
$valid = false;
}
$valid return;
}The code excludes the product ID we specify from the discount. For example, in our case, the product ID is 145, and the code fragment is as follows:
add_filter( ‘woocommerce_coupon_is_valid_for_product’, ‘quadlayers_exclude_product_from_product_promotions’, 9999, 4 );
Functions quadlayers_exclude_product_from_product_productions ($valid, $product, $coupon, $values){
\/\/Product id = 145
if ( 145 == $product->get_id() ) {
$valid = false;
}
$valid return;
} 
That’s all! Exclude all products from the specified coupon. See the site for more information. 2.2) in addition to woocommerce products sold on coupons, another interesting option is to exclude products with discounts already applied from the coupon code. For example, if you already have a product on sale, you can add scripts to avoid additional discounts. This is useful if the store has an ongoing sales promotion and you want to ensure that the discount does not apply to the product being sold. This process is similar to the above process. On the administration dashboard, navigate to shapes > Theme Editor and use functions in the theme file sidebar on the right. Just open the PHP file. Then paste the following script to exclude all sold products from the discount:
add_filter(‘xa_pbu_skip_product_on_sale’,’ql_skip_product_on_sale_from_discount’,1,2);
Function sql_skip_product_on_sale_from_discount ($return_val, $PID){
$sale_price = get_post_meta( $pid,’_sale_price’,true );
if( !empty($sale_price) ) {
Returns true\/\/ If true, this product is excluded
}
Return $return_val;
} 
Or use the following code to remove a specific product that has been sold from the coupon
ate_option( ‘_products_disabled_for_coupons’, $disabled_products );
}
\/\/Invalidate coupons at the product level.
add_filter(‘woocommerce_coupon_is_valid_for_product’, ‘set_coupon_validity_for_excluded_products’, 12, 4);
Function set_coupon_validity_for_excluded_products ($valid, $product, $coupon, $values){
if(!count(get_option)(“_products_disabled_for_coupons”)>0)$valid。
$disabled_products = get_option( ‘_products_disabled_for_coupons’ );
if( in_array( $product->get_id(), $disabled_products ) )
$valid = false;
$valid return;
}
\/\/Set the product discount amount to 0
add_filter( ‘woocommerce_coupon_get_discount_amount’, ‘zero_discount_for_excluded_products’, 12, 5 );
function zero_discount_for_excluded_products($discount, $discounting_amount, $cart_item, $single, $coupon ){
If (! Count (get_option) (\
$disabled_products = get_option( ‘_products_disabled_for_coupons’ );
if( in_array( $cart_item[‘product_id’], $disabled_products ) )
$discount = 0;
Return $discount;
}Then update the file. Now let’s look at how to use the custom check box we just added. Go to the \