Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

332
Vistas
Coupon discount on product regular price (not sale price)

In WooCommerce, I have products with a regular price of X and a sales price of Y. I would like to add a coupon with a code for a $45.00 discount to be taken from the regular price X.

I would like the coupon to disregard the sale price so I get X-$45 NOT Y-$45. But when the coupon is not applied price Y is used.

I found the following which works for percentage discounts, but I can't seem to make it work for a fixed product discount price.

add_filter('woocommerce_coupon_get_discount_amount', 'woocommerce_coupon_get_discount_amount', 10, 5 );
function woocommerce_coupon_get_discount_amount( $discount, $discounting_amount, $cart_item, $single, $coupon ) {
    if ($coupon->type == 'percent_product' || $coupon->type == 'percent') {
        global $woocommerce;
        $cart_total = 0;

        foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $cart_item ) {

         $variable_product1= new WC_Product_Variation( $cart_item["variation_id"] );

         $cart_total += $variable_product1 ->regular_price * $cart_item['quantity'];
        } 
        $discount = round( ( $cart_total / 100 ) * $coupon->amount, $woocommerce->cart->dp );
        return $discount;
    }
    return $discount;
}
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

This seems to check for a coupon and then change the cart price to regular price rather than discounted price (obtained from woocommerce dynamic pricing in this application) prior to applying the coupon. placed in functions.php

add_action( 'woocommerce_before_calculate_totals', 'add_custom_price', 10, 1);
function add_custom_price( $cart_object) {

    global $woocommerce;

    if ( is_admin() && ! defined( 'DOING_AJAX' ) )
        return;

    $coupon = False;

    if ($coupons = WC()->cart->get_applied_coupons()  == False ) 
      $coupon = False;
    else {
        foreach ( WC()->cart->get_applied_coupons() as $code ) {
          $coupons1 = new WC_Coupon( $code );
          if ($coupons1->type == 'percent_product' || $coupons1->type == 'percent')
            $coupon = True;
        }
    }

    if ($coupon == True)
        foreach ( $cart_object->get_cart() as $cart_item ) 
        {
            $price = $cart_item['data']->regular_price;
            $cart_item['data']->set_price( $price );
        }
}
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda