The PHP code in this download folder enables you to set a percentage discount on a per product basis conditionally and :
- Target products in specific categories
- Target products with specific tags
- Make products on sale with a percentage discount
- Strike out the regular price and show the discounted price by its side
The input field for the percentage discount is shown conditionally on the Edit product screen for products in specific taxonomy terms.
The regular price is shown with a strike through and the discounted price displayed beside it.
Code Installation
Simple one step copy & paste of the PHP code to the end of your child themes functions file or custom functionality plugin.
Targeting Specific Categories & Tags
Modify the parameters in this line of code with your taxonomy name and taxonomy type:
For product tags use product_tag
like this ;
has_term( 'discount', 'product_tag' )
Where discount is your tag name and product_tag
is the name of your taxonomy.
For product categories use product_tag
like this ;
has_term( 'discount', 'product_cat' )
Where discount is your category name and product_cat
is the name of your taxonomy.
You can also target taxonomy terms using the ! not operator like this :
if ( ! has_term( 'discount', 'product_cat' ) )
return;
In this case, the code will return early if the product category is not named discount and not execute.
Leave a Reply