0

I am looking for a snippet to Edit WooCommerce Prices Programmatically for ALL products: Simple Products and Product variations

The best I've found is this method which uses a coupon. Problem for me is that this method does not really modify the price but apply the the coupon instead.

- I need a code to really modify the price for all products

- Doing this in the Database would be a right method too.

add_action( 'woocommerce_before_cart', 'quadlayers_coupon_individual_products' );

function quadlayers_coupon_individual_products () {

$coupon_code = 'quadlayers30'; //Use your coupon code between single quotes' '

if ( WC()->cart->has_discount( $coupon_code ) ) return;
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
    $autocoupon = array( 2970 ); //Use your product ID inside the array( id )
    if ( in_array( $cart_item['product_id'], $autocoupon ) ) {
       WC()->cart->apply_coupon( $coupon_code );
       wc_print_notices();
    }
}
}
JPashs
  • 13,044
  • 10
  • 42
  • 65
  • From what I understand from your question you want to adjust the prices in cart (based on the current hook you are using, since it applies in/on cart), if not please clarify your question – 7uc1f3r Feb 25 '22 at 11:39
  • No, I think it is already clear in my question: "Problem for me is that this method does not really modify the price but apply the the coupon instead." "I need a code to really modify the price for all products" I don't know how to clarify this more. – JPashs Feb 25 '22 at 15:04

0 Answers0