F
F
fqgtq2020-08-02 12:44:00
WooCommerce
fqgtq, 2020-08-02 12:44:00

How to make the discount amount in money?

There is a plugin, WooCommerce Advanced Product Labels. He makes stickers for products "discount size in%". How can I make it also display the amount of the discount in money?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
Lord_Dantes, 2020-08-02
@Lord_Dantes

Replace the function of displaying the size of the discount as a percentage with a calculation formula in money and withdraw money.
Make a backup of the desired function in advance.

P
Pychev Anatoly, 2020-08-02
@pton

Look in the plugin under the hood.
You can find this code there

/**
 * SMART labels.
 *
 * Add filter to convert SMART labels.
 *
 * @since 1.0.0
 *
 * @param  string $label Label text value.
 * @return string        Modified label text value.
 */
function wapl_smart_product_label_filter( $label ) {

  global $product;

        ... 

  $label = str_replace( '{percentage}', round( $highest_percentage, apply_filters( 'wapl_filter_discount_round', 1 ) ) . '%', $label );
  $label = str_replace( '{discount}', wc_price( (float) $regular_price - (float) $sale_price ), $label );
  $label = str_replace( '{price}', wc_price( $regular_price ), $label );
  $label = str_replace( '{saleprice}', wc_price( $sale_price ), $label );
  $label = str_replace( '{delprice}', '<del>' . wc_price( $regular_price ) . '</del>', $label );

  return $label;
}
add_filter( 'wapl_product_label', 'wapl_smart_product_label_filter' );

As a result, all you need is to fill in the "Text" field of the created label with the necessary replace-word {discount} или {price} или ..., or process the filter'wapl_product_label'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question