php - Woocommerce discount if has certain attribute -
Each product in my database is a "pa_producator" attribute, and I want the following thing: when pa_producator "Bosch", that Apply only 10% discount on the product, not the entire cart Is this possible? So far, I only have the following code:
add_action ('woocommerce_before_cart_table', 'discount_producer'); Function discount_producer () {global $ woocommerce; $ Test = $ woocommerce- & gt; Cart- & gt; Get_cart (); Foreign currency ($ test as $ product) {$ test = get_the_terms ($ product ['product_id'], 'pay_productcutter'); $ Productive = $ test [0] - & gt; Name; }} How do I apply a discount for those products?
It is better to update prices before any output, so it will apply to all the places where the cart Is used.
add_action ('woocommerce_cart_loaded_from_session', 'check_art_items', 99, 1); The search for this action is created right after the cart has been created, then you can adjust the value for each item in the cart.
public function check_cart_items ($ cart) {foreach ($ cart-> cart_contents $ key = & gt; $ as product) {// Detect attribute for current product // Luggage $ cart- & gt; Cart_saint [$ key] ['data'] - & gt; Value = $ new_price; $ Cart- & gt; Cart_saint [$ key] ['data'] - & gt; Regular_price = $ value; $ Cart- & gt; Cart_saint [$ key] ['data'] - & gt; Sales_price = $ value; }}
Comments
Post a Comment