T
T
trenton2021-04-28 01:14:52
WooCommerce
trenton, 2021-04-28 01:14:52

How to display the sale price and the usual price for variations side by side?

They are not a select, that's where I got the code from https://stackoverflow.com/questions/36219833/wooco... - a good alternative to plugins by the way, if there is no photo in each variation, if there is, then switchers are better.
I customized it for myself, and the part with variations is displayed like this

$radios .= '<div class="attr-container"><div class="radio-span d-flex"><div class="radio-button"><input type="radio" id="'.esc_attr($id).'" name="'.esc_attr($name).'" value="'.esc_attr($term->slug).'" '.checked(sanitize_title($args['selected']), $term->slug, false).'></div><div class="radio-label"><label for="'.esc_attr($id).'">'.esc_html(apply_filters('woocommerce_variation_option_name', $term->name)). '</label></div>' . !!!!!! . '</div></div>';

Here in a piece with exclamation marks I need 2 prices.
I try like this, but only the usual one is displayed, how else can I?
$price = get_post_meta( get_the_ID(), '_regular_price', true);
$sale = get_post_meta( get_the_ID(), '_price', true);
if (!empty($sale)){
  echo $sale;
} else {
  echo $price;
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question