0

By default wooCommerce displays price as "Regular price" first and "Sale price" second. I wish to reverse the order for all types (simple,variation,...). Is this possible? How?

Thx

0

You're going to want to use hooks and filters to change that. I would look at the woocommerce_get_price_html and/or woocommerce_variable_price_html filters.

EDIT:

here is the core WC code you need to alter:

/**
 * Format a sale price for display.
 *
 * @since  3.0.0
 * @param  string $regular_price Regular price.
 * @param  string $sale_price    Sale price.
 * @return string
 */
function wc_format_sale_price( $regular_price, $sale_price ) {
    $price = '<del>' . ( is_numeric( $regular_price ) ? wc_price( $regular_price ) : $regular_price ) . '</del> <ins>' . ( is_numeric( $sale_price ) ? wc_price( $sale_price ) : $sale_price ) . '</ins>';
    return apply_filters( 'woocommerce_format_sale_price', $price, $regular_price, $sale_price );
}

as you can see, there's a filter on the returned value. what you want ot do is hook into that filter and return the prices how you want. something like this:

add_filter('woocommerce_format_sale_price', 'wc_override_sale_price_format', 10, 2);
function wc_override_sale_price_format( $regular_price, $sale_price ) {
    $price = '<ins>' . ( is_numeric( $sale_price ) ? wc_price( $sale_price ) : $sale_price ) . '</ins> <del>' . ( is_numeric( $regular_price ) ? wc_price( $regular_price ) : $regular_price ) . '</del>';
    return $price;
}
  • I did this, but the $product->get_regular_price() is retuning 0 for variable products. – Benmay Dec 21 '18 at 14:16
  • @Benmay I mocked something up for you. Modify as you need – mrben522 Dec 21 '18 at 14:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.