Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

199
Views
WooCommerce: agregue un descuento basado en la cantidad de artículos individuales

En mi sitio web de WooCommerce tengo algunos productos con el mismo precio de 80$ .
Quiero agregar un descuento por la cantidad de productos.

La lógica es así:

 if (Products Quantity is 2){ // the original product price change from 80$ to 75$ each. } if(Products Quantity is 3 or more){ //the original product price change from 80$ to 70$ each. }

por ejemplo,

si un cliente elige 2 productos, el precio original será (80$ x 2) => 160$ .
Pero después del descuento, será: (75$ x 2) => 150$ .

Y…

si el visitante elige 3 productos, el precio original será (80$ x 3) => 240$ .
Pero después de la tarifa, será: (70$ x 3) => 210$ .

¿Alguna ayuda, por favor?

Gracias

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Esta función enganchada personalizada debería hacer lo que espera. Puede establecer en él su límite de descuento progresivo basado en la cantidad de artículos individuales.

Aquí está el código

 ## Tested and works on WooCommerce 2.6.x and 3.0+ add_action( 'woocommerce_cart_calculate_fees', 'progressive_discount_by_item_quantity', 10, 1 ); function progressive_discount_by_item_quantity( $cart ) { if ( is_admin() && ! defined( 'DOING_AJAX' ) ) return; # Progressive quantity until quantity 3 is reached (here) # After this quantity limit, the discount by item is fixed # No discount is applied when item quantity is equal to 1 // Set HERE the progressive limit quantity discount $progressive_limit_qty = 3; // <== <== <== <== <== <== <== <== <== <== <== $discount = 0; foreach( $cart->get_cart() as $cart_item_key => $cart_item ){ $qty = $cart_item['quantity']; if( $qty <= $progressive_limit_qty ) $param = $qty; // Progressive else $param = $progressive_limit_qty; // Fixed ## Calculation ## $discount -= 5 * $qty * ($param - 1); } if( $discount < 0 ) $cart->add_fee( __( 'Quantity discount' ), $discount); // Discount }

El código va en el archivo function.php de su tema secundario activo (o tema) o también en cualquier archivo de complemento.

Probado y funciona en WooCommerce 2.6.x y 3.0+

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!