Forum Replies Created

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter ibrar45

    (@ibrar45)

    Here’s the code:

    // Cheapest Price
    
     add_filter( 'woocommerce_variable_sale_price_html', 'wc_wc20_variation_price_format', 10, 2 );
     add_filter( 'woocommerce_variable_price_html', 'wc_wc20_variation_price_format', 10, 2 );
    
     function wc_wc20_variation_price_format( $price, $product ) {
         // Main Price
         $prices = array( $product->get_variation_price( 'min', true ), $product->get_variation_price( 'min', true ) );
         $price = $prices[0] !== $prices[1] ? sprintf( __( '%1$s', 'woocommerce' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] );
    
         // Sale Price
         $prices = array( $product->get_variation_regular_price( 'min', true ), $product->get_variation_regular_price( 'min', true ) );
         sort( $prices );
         $saleprice = $prices[0] !== $prices[1] ? sprintf( __( '%1$s', 'woocommerce' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] );
    
         if ( $price !== $saleprice ) {
             $price = '<del>' . $saleprice . '</del> <ins>' . $price . '</ins>';
         }
    
         return $price;
     }
    
     add_action( 'woocommerce_before_single_product', 'move_variations_single_price', 1 );
     function move_variations_single_price(){
         if ( ! is_product() ) return; // Only on single product pages
    
         global $product, $post;
    
         if ( $product->is_type( 'variable' ) ) {
             // removing the variations price for variable products
             remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
             // Change location and inserting back the variations price
             add_action( 'woocommerce_single_product_summary', 'replace_variation_single_price', 10 );
         }
     }
    
     function replace_variation_single_price(){
        global $product;
    
          // Main Price
          $prices = array( $product->get_variation_price( 'min', true ), $product->get_variation_price( 'min', true ) );
          $price = $prices[0] !== $prices[1] ? sprintf( __( '%1$s', 'woocommerce' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] );
    
         // Sale Price
      $prices = array( $product->get_variation_regular_price( 'min', true ), $product->get_variation_regular_price( 'min', true ) );
      sort( $prices );
     $saleprice = $prices[0] !== $prices[1] ? sprintf( __( '%1$s', 'woocommerce' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] );
    
     if ( $price !== $saleprice && $product->is_on_sale() ) {
          $price = '<del>' . $saleprice . $product->get_price_suffix() . '</del> <ins>' . $price . $product->get_price_suffix() . '</ins>';
      }
    
      ?>
    
         <script>
         jQuery(document).ready(function($) {
             $('select').blur( function(){
                 if( '' != $('input.variation_id').val() ){
                     if($('p.availability'))
                         $('p.availability').remove();
                     $('p.price').html($('div.woocommerce-variation-price > span.price').html()).append('<p class="availability">'+$('div.woocommerce-variation-availability').html()+'</p>');
                     console.log($('input.variation_id').val());
                 } else {
                     $('p.price').html($('div.hidden-variable-price').html());
                     if($('p.availability'))
                         $('p.availability').remove();
                     console.log('NULL');
                 }
             });
         });
         </script>
    <?php
    
     }
    Thread Starter ibrar45

    (@ibrar45)

    The website is not live right now so I cant provide you a link to it..I was thinking about buying the plugin…but it seems that it might be causing this issue due to custom php code for variable products .. but will I face this issue even if I buy the plugin??
    If so it will great if I can get support for this issue..

Viewing 2 replies - 1 through 2 (of 2 total)