I am a new member and is weak in programer. I want display Sale price before Regular price (as images attach). I determined the hook here is woocommerce_before_variations_form. Here is the code to edit in the hook.
// define the woocommerce_before_variations_form callback
function action_woocommerce_before_variations_form () {
// make action magic happen here ...
};
// add the action
add_action ('woocommerce_before_variations_form', 'action_woocommerce_before_variations_form', 10, 0);
Can you help me display Sale price before Regular price?
For example, a $20 item discounted to $15 should display “25% off” (and not “$5 off”), whereas items priced above $100 should generally display the discount in absolute numbers; for instance, a $1,000 item discounted to $900 should display “$100 off” (and not “10% off”).
This is what we need to change the price position. Create a new JS by clicking on "Custom CSS & JS > Add Custom JS". Copy and paste the JS code below and save the JS code. You're done, now you can see the price position has moved from top to page bottom.
Go to: Product > Product X (the product you wish to set a rule for). Next, go to: Product Data > Dynamic pricing. Select Add Pricing Group. There, configure the conditions for the rule.
Get the price of a simple procut php #the product must be instantiated above like $product = new WC_Product(); echo $product->regular_price; echo $product->sale_price; ?> If the product has variations you will get nothing if you will use the code above. You need to get the variation product prices.
The following hooked function code will display the Sale price before Regular price:
add_filter( 'woocommerce_format_sale_price', 'invert_formatted_sale_price', 10, 3 );
function invert_formatted_sale_price( $price, $regular_price, $sale_price ) {
return '<ins>' . ( is_numeric( $sale_price ) ? wc_price( $sale_price ) : $sale_price ) . '</ins> <del>' . ( is_numeric( $regular_price ) ? wc_price( $regular_price ) : $regular_price ) . '</del>';
}
Code goes in function.php file of the active child theme (or active theme). Tested and works.
You can solve this using only jQuery and swap to element that show the regular price and sale price:
$("#element1").before($("#element2"));
or
$("#element1").after($("#element2"));
:)
and one more on js fiddle https://jsfiddle.net/nak73406/v9k7b5c1/5/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With