0

I currently have the following products in the database:

Database

Woocommerce is currently using the "price" field. I want to make it so that if "price_percent" is greater than 0, it would add the "price_percent" discount to the price, and use the new price instead.

Basically when I open the cart, I want to have the discounted price and bill the customer for it (if there is a discount).

Pretty new to WooCommerce/Wordpress so I'm not sure where to do this.

1 Answer 1

1

You can use this filter in your theme or plugin to filter the product prices:

function filter_woocommerce_price( $price, $product ) { 

    // 1. Set your $price_percent variable
    // 2. Subtract the price_percent from the price $price - $price_percent
    // 3. Set the new $price

    return $price;
} 
add_filter( 'woocommerce_product_get_regular_price', 'filter_woocommerce_price', 10, 2 );

By the way - you can use $product->get_id() within function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.