T
T
TrixieBek2020-09-07 20:43:23
WooCommerce
TrixieBek, 2020-09-07 20:43:23

How to display woocommerce variations in price tag?

Good afternoon, is it possible to display variations in the price tag?
5f56713a05111635702870.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Litvinenko, 2020-09-08
@AntonLitvinenko

if ( $product->is_type('variable') ) {

  foreach ( $product->get_available_variations() as $variation ) {

    foreach ( wc_get_product($variation['variation_id'])->get_variation_attributes() as $attr ) {
      echo wc_attribute_label( $attr );
    }

    $active_price = floatval($variation['display_price']);
    $regular_price = floatval($variation['display_regular_price']);

    if ( $active_price != $regular_price ){
      $sale_price = $active_price;
    }

    echo '<span class="variation-prices"><strong>Price</strong>: '.$variation['price_html'].'</span><br>';

  }

}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question