• Resolved sanch3x

    (@sanch3x)


    When I var_dump the variation values for my product the whole mention of a wholesale price is in the price_html variable. display_price and display_regular_price are both the regular price but you’d think your plugin would overtake display_price when a wholesale price should be displayed.

    Where does one get this value if they are using heavily edited template files?

    For example, this is how I cycle through my variations to display prices:

    $variations = $product->get_available_variations();
    foreach( $variations as $variation ) {
      echo wc_price( $variation['display_price'] );
    }
Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Josh Kohlbach

    (@jkohlbach)

    Hi @sanch3x,

    Thanks for the question.

    We don’t exactly take over the price, we adjust it with various filters.

    You should be able to just fetch the variation of the product and call get_price_html() like so:

    $variation_product = wc_get_product( $variation[ 'variation_id' ] );
    echo $variation_product->get_price_html();

    Hope this helps!

    Thread Starter sanch3x

    (@sanch3x)

    Hi Josh,

    Thank you for the quick reply, it’s much appreciated. The only problem with get_price_html() is that I want the numeric value of the price (without markup) because I use it to calculate the cost per unit. So a $20 box of 20 items is $1 per item. Basically it’s a quick way to show a client the best value.

    Is there a similar call for just the numeric value? $variation_product->get_price() only returns the regular price.

    Thread Starter sanch3x

    (@sanch3x)

    Okay, so it’s not the most elegant solution but with the assumption that the client will continue to only support their default currency, the following currently works:

    if( self::get_user_role() == 'wholesale_customer' ) {
    			if( $wholesale_price = get_post_meta( $default_variation_id , 'wholesale_customer_wholesale_price' , TRUE ) ) {
    				$price = $wholesale_price;
    			}
    		}

    Basically I check to see if the user role is a wholesale_customer (the only available wholesale role with the free version) and then check to see if the base/raw price exists. If it does I replace my default price value.

    It seems to work but I know it would break in certain situations like, as mentioned, there are different currencies or the websites upgrades to the pro version.

    Plugin Author Josh Kohlbach

    (@jkohlbach)

    Hi @sanch3x,

    My pleasure. You’re pretty close there.

    What you can probably do is use our function for fetching the price on shop instead and it will take care of all that testing for you.

    We’ve spun up a little code for you which should do the job:

    add_action( 'init' , function() {
       
        // some code here to loop and get all variations
    
        global $wc_wholesale_prices;
        $foo = $wc_wholesale_prices->wwp_wholesale_prices->get_product_wholesale_price_on_shop( $variation_id , $wc_wholesale_prices->wwp_wholesale_roles->getUserRoles() );
    
        error_log( $foo );
    
    } );

    Hope this helps!

    • This reply was modified 7 years, 3 months ago by Josh Kohlbach.
    Plugin Author Josh Kohlbach

    (@jkohlbach)

    Hi @sanch3x,

    Sorry made a typo:

    add_action( 'init' , function() {
       
        // some code here to loop and get all variations
    
        global $wc_wholesale_prices;
        $foo = $wc_wholesale_prices->wwp_wholesale_prices->get_product_wholesale_price_on_shop( $variation_id , $wc_wholesale_prices->wwp_wholesale_roles->getUserWholesaleRole() );
    
        error_log( $foo );
    
    } );
    Thread Starter sanch3x

    (@sanch3x)

    That looks like a solution that won’t break if I sneeze on it.

    Thank you very much for taking the time.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Where is the wholesale price held?’ is closed to new replies.