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

271
Views
WooCommerce cómo mostrar "usted ahorra X%" en la página de pago

Creé una función que muestra al finalizar la compra los ahorros totales en función de los descuentos de productos, pero me gustaría que mostrara el porcentaje ahorrado sobre el total del pedido y, si es posible, mostrarlo dentro de un cuadro.

Código:

 function wc_discount_total() { global $woocommerce; $discount_total = 0; foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $values) { $_product = $values['data']; if ( $_product->is_on_sale() ) { $regular_price = $_product->get_regular_price(); $sale_price = $_product->get_sale_price(); $discount = ($regular_price - $sale_price) * $values['quantity']; $discount_total += $discount; } } if ( $discount_total > 0 ) { echo '<tr class="cart-discount"> <th>'. __( 'Your Savings', 'woocommerce' ) .'</th> <td data-title=" '. __( 'You Saved', 'woocommerce' ) .' ">' . wc_price( $discount_total + $woocommerce->cart->discount_cart ) .'</td> </tr>'; } } add_action( 'woocommerce_cart_totals_after_order_total', 'wc_discount_total', 99); add_action( 'woocommerce_review_order_after_order_total', 'wc_discount_total', 99);

Cómo se ve mi pago actual:

ingrese la descripción de la imagen aquí

Ampliado:

ingrese la descripción de la imagen aquí

Como me gustaria que se viera:

ingrese la descripción de la imagen aquí

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Si hay un descuento en ese pedido, puede agregar otra etiqueta de fila de tabla y calcular el porcentaje. Así que sería algo como esto:

 add_action('woocommerce_cart_totals_after_order_total', 'wc_discount_total', 99); add_action('woocommerce_review_order_after_order_total', 'wc_discount_total', 99); function wc_discount_total() { global $woocommerce; $discount_total = 0; foreach ($woocommerce->cart->get_cart() as $cart_item_key => $values) { $_product = $values['data']; if ($_product->is_on_sale()) { $regular_price = $_product->get_regular_price(); $sale_price = $_product->get_sale_price(); $discount = ($regular_price - $sale_price) * $values['quantity']; $discount_total += $discount; } } if ($discount_total > 0) { echo '<tr class="cart-discount"> <th>' . __('Your Savings', 'woocommerce') . '</th> <td data-title=" ' . __('You Saved', 'woocommerce') . ' ">' . wc_price($discount_total + $woocommerce->cart->discount_cart) . '</td> </tr>'; $total = WC()->cart->cart_contents_total; $total_saved = wc_price($discount_total + $woocommerce->cart->discount_cart); $percentage_saved = round(($total_saved * 100) / $total); echo '<tr class="cart-percentage-discount"> <th>' . __('Percentage Saved', 'woocommerce') . '</th> <td data-title=" ' . __('You Saved', 'woocommerce') . ' ">' . esc_html($percentage_saved . "%") . '</td> </tr>'; } }
over 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!