• Hi,

    I wanted to do the following

    Get the variable product sale price percentage in separate per variation. I tried the following

    $available_variations = $product->get_available_variations();
     $maximumper = 0;
     for ($i = 0; $i < count($available_variations); ++$i) {
         $variation_id=$available_variations[$i]['variation_id'];
         $variable_product1= new WC_Product_Variation( $variation_id );
         $regular_price = $variable_product1 ->regular_price;
         $sales_price = $variable_product1 ->sale_price;
         $percentage= round((( ( $regular_price - $sales_price ) / $regular_price ) * 100),1) ;
          echo $price . sprintf( __('%s', 'woocommerce' ), $percentage . '<span class="main_sale_percentage_sign">%</span></p>');
      }

    But by this code am getting all variations percentages. How i can get them in separate so i can display one per click on variation change?

    Thanks in advance.

    https://www.ads-software.com/plugins/woocommerce/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor Mike Jolley (a11n)

    (@mikejolley)

    We really cannot keep helping with custom coding on this forum, it’s out of scope. I’m happy to help solve bugs and give general guidance, but if you look at your history its all custom code…

    As I mentioned previously, if you need a developer:

    https://www.woothemes.com/experts/
    jobs.wordpress.net

    Just general feedback, don’t use new WC_Product_Variation(. Use the wc_get_product() function.

    Your code is just echoing the prices in one huge blob. I don’t know what you’re doing with it, but I think you want to use the woocommerce_get_price_html filter instead.

    Thread Starter anahitipoint

    (@anahitipoint)

    Hey it is not a custom code.

    I just need to get active variation price per avaliable product variations so i can do some calculations with current sale and regular price.

    Is there a way to get active variation price?

    Thanks!

    Caleb Burks

    (@icaleb)

    Automattic Happiness Engineer

    How is this not custom code? This is literally the definition of custom code…

    Since variations are changed on the front-end, you can’t get the current active variation’s price via just PHP. You’ll need to do this with some javascript as well like core does: https://github.com/woothemes/woocommerce/blob/master/assets/js/frontend/add-to-cart-variation.js

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How i can get variable product sale price percentages in separate’ is closed to new replies.