Answer the question
In order to leave comments, you need to log in
How to override get_price_html() for variable products?
Hello. There is a shop on wordpress + woocommerce. I have this question: to display the price in the product section, the get_price_html() output function is used . How to redefine it for variable products so that the price tag is not displayed as Range: old price - old price Range: new price - new price (i.e. 120,000 rubles - 180,000 rubles 90,000 rubles - 150,000 rubles) ?
<div class="price"><del><span class="amount">120.000 руб.</span>–<span class="amount">180.000 руб.</span></del> <ins><span class="amount">90.000 руб.</span>–<span class="amount">150.000 руб.</span></ins></div>
<?php global $product, $post;
if($product->product_type == 'variable') {
$variable_products = array(
'available_variations' => $product->get_available_variations(),
'attributes' => $product->get_variation_attributes(),
'selected_attributes' => $product->get_variation_default_attributes()
);
if ( ! empty( $variable_products['available_variations'] ) ) : ?>
<table class="variations" cellspacing="0">
<tbody>
<?php $loop = 0; foreach ( $variable_products['attributes'] as $name => $options ) : $loop++; ?>
<tr>
<td class="label"><label for="<?php echo sanitize_title($name); ?>"><?php echo wc_attribute_label( $name ); ?></label></td>
<td class="value"><select id="<?php echo esc_attr( sanitize_title( $name ) ); ?>" name="attribute_<?php echo sanitize_title( $name ); ?>">
<?php
if ( is_array( $options ) ) {
if ( isset( $_REQUEST[ 'attribute_' . sanitize_title( $name ) ] ) ) {
$selected_value = $_REQUEST[ 'attribute_' . sanitize_title( $name ) ];
} elseif ( isset( $variable_products['selected_attributes'][ sanitize_title( $name ) ] ) ) {
$selected_value = $variable_products['selected_attributes'][ sanitize_title( $name ) ];
} else {
$selected_value = '';
}
// Get terms if this is a taxonomy - ordered
if ( taxonomy_exists( sanitize_title( $name ) ) ) {
$orderby = wc_attribute_orderby( sanitize_title( $name ) );
switch ( $orderby ) {
case 'name' :
$args = array( 'orderby' => 'name', 'hide_empty' => false, 'menu_order' => false );
break;
case 'id' :
$args = array( 'orderby' => 'id', 'order' => 'ASC', 'menu_order' => false, 'hide_empty' => false );
break;
case 'menu_order' :
$args = array( 'menu_order' => 'ASC', 'hide_empty' => false );
break;
}
$terms = get_terms( sanitize_title( $name ), $args );
foreach ( $terms as $term ) {
if ( ! in_array( $term->slug, $options ) )
continue;
echo '<option value="' . esc_attr( $term->slug ) . '" ' . selected( sanitize_title( $selected_value ), sanitize_title( $term->slug ), false ) . '>' . apply_filters( 'woocommerce_variation_option_name', $term->name ) . '</option>';
}
} else {
foreach ( $options as $option ) {
echo '<option value="' . esc_attr( sanitize_title( $option ) ) . '" ' . selected( sanitize_title( $selected_value ), sanitize_title( $option ), false ) . '>' . esc_html( apply_filters( 'woocommerce_variation_option_name', $option ) ) . '</option>';
}
}
}
?>
</select></td>
</tr>
<?php endforeach;?>
</tbody>
</table>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question