Skip Navigation

[Résolu] wpv-woo-product-price shortcode with variable products

This support ticket is created Il y a 7 années et 3 mois. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

Marqué : 

This topic contains 13 réponses, has 2 voix.

Last updated by timB Il y a 7 années et 3 mois.

Assisted by: Minesh.

Auteur
Publications
#474245
PricingTable.png

Using WooCommerce with Views, I'm trying to get variable product prices displayed how my client wants them.

We're using the [wpv-woo-product-price] shortcode which, according to the reference at this page:

https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-woo-product-price

... should output the price how the client wants it. As it says...:

For Variable products, the lowest price for a Variation will be displayed, preceded by the text “From”.

However, as the screenshot attached shows, its actually displaying it as {MinPrice}-{MaxPrice}

If we weren't showing multiple currencies for products then I could just bring in the {_min_variation_price} value from Woo's own custom fields, however, there is functionality which sets the price and currency according to the user's location.

I looked at this support thread, which was helpful:

https://toolset.com/forums/topic/multi-variation-price-display/

But I don't want to change WooCommerce plugin files if I can help it. Perhaps a custom function would do it...? - Better still, can someone tell me if its possible to use another shortcode, or anything else which can be done to show the lowest price for a variation preceded by the text "From" as is specified in the shortcode reference?

Thanks

#474454

Minesh
Supporter

Languages: Anglais (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Could you please try following shortcode to dispaly the price:

From: [types field='views_woo_price' output='raw'][/types]

As far as I know above shortcode will be enough to display the price.

#474490
prodlisting.png

Thank you for that Minesh.
I tried using the code you proposed for variable products accordingly, however it returned null (see the image attached). The top two rows are variable woo products here, and the second two simple woo products.

The column displaying the amount and price is produced by a nested view with the following. This way it can display the woo-driven product price for simple and variable products accordingly. :

	<!-- wpv-loop-start -->
		<wpv-loop>
          [types field="display-amount" output="raw"]:
          [wpv-conditional if="( $(wpcf-has_varieties) ne '1' )"]
                       [wpv-woo-product-price]
          [/wpv-conditional]
          [wpv-conditional if="( $(wpcf-has_varieties) eq '1' )"]         
                       From: [types field='views_woo_price' output='raw'][/types]
          [/wpv-conditional]
		</wpv-loop>
	<!-- wpv-loop-end -->

Have you any other suggestions please...

Thank you
Tim

#474493

Minesh
Supporter

Languages: Anglais (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can I look into your install please. Could you please share problem URL where I can see the info attached in the screenshot.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).

I have set the next reply to private which means only you and I have access to it.

#476500

Minesh
Supporter

Languages: Anglais (English )

Timezone: Asia/Kolkata (GMT+05:30)

The field views_woo_price is null most likely because they are not yet calculated. This needs to be calculated first before its usable by Toolset:

To calculate the price, navigate to:
=> Toolset => WooCommerce Views
=> Navigate to section: Static Product Fields for Parametric Searches
=> Select 'Manually' and then click 'Calculate Now'

This should set the views_woo_price with a value. Please let our client try this before we go further.

More info:
https://toolset.com/documentation/woocommerce-views-calculated-fields-and-batch-update/#wcv-update-calculated

Could you please try this and let me know if this help you to resolve your issue.

#476512
pricing-meta.png

Hi Minesh

Thanks for that. OK we have run the manual update accordingly, however I'm afraid the field still shows null when we uncomment this code for Variable Products:

 [types field='views_woo_price' output='raw'][/types] 

This is strange, because I can see the views_woo_price field in the postmeta table (see attached) for one of the products we're dealing with... with post_id 15281 - first in the list on this page:
hidden link

Can you suggest what else we should do? - and can you assure me the price will still be correct whether users are viewing in EUR or $ ...

Thanks
Tim

#476812

Minesh
Supporter

Languages: Anglais (English )

Timezone: Asia/Kolkata (GMT+05:30)

Could you please check now. I've used following shortcode and now I can see the price is displaying 240:

[wpv-post-field name='views_woo_price']
#476828

Thank you Minesh

I can see the field is displaying now, but shows more than once for several items in the list - it even shows four times, separated by a comma, for some items further down the list.

The currency icon doesn't show (£/$/€), and when changing the currency with the drop-down (top right) the price doesn't change, although you'll see it does for simple products (non-variable). (we have fixed prices set up per currency with this Woocommerce install).

Are we using the correct field therefore, or should we be forcing the use of woocommerce's simple product method instead?

I appreciate this is a tricky one, so your determination to help us fix it will be much appreciated.

Tim

#476830

Minesh
Supporter

Languages: Anglais (English )

Timezone: Asia/Kolkata (GMT+05:30)

I checked on your plugins page and I found that you are using outdated Woocommerce views + Woocommerce plugin.

Could you please update ALL Toolset + WC + Woocommerce views to its latest official released version and check if latest version help you to fix the issue.

#476863

Hi Minesh

OK - I've updated all plugins, but the issue remains the same:
hidden link

Tim

#476878

Minesh
Supporter

Languages: Anglais (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well, I investigate further and I see the really strange thing.

For example, the following post has two child products in a relation which was displaying "views_woo_price" two times:
=> hidden link

That you can see here:
=> hidden link

So following are child products:
=> Anti-Fluorescein [4-4-20 (enhanced)] Standard size, 200 μg, Ab00102-10.6 (has_archive=YES)
=> Anti-Fluorescein [4-4-20 (enhanced)] Bulk size, 1 mg, Ab00102-10.6-BT(has_archive=YES)

Now, the product's ID of (has_archive=YES) is 18003. When I checked in postmeta table and search the postmeta with post ID 18003, the strange thing I found is there is "views_woo_price" available for two times. See following screenshot:
=> hidden link

So, as there are two entries available for "views_woo_price" I deleted one entry from postmeta table and now you can see in the following list that for post "Ab00102-10.6 Anti-Fluorescein [4-4-20 (enhanced)]" there is only one time "views_woo_price" displayed :
=> hidden link

Could you please check for other posts which is dispalying "views_woo_price" more than one time.

#476916

Hi Minesh, thanks for your investigation.

That is a strange thing. But I think it is pulling us sideways from the main problem.
There are four crucial woocommerce custom fields, which are generated each time a variable product is created. These, and the 'max' equivalents are used in the default shortcode to display {minprice} - {maxprice} for variable products:

_min_variation_price
_usa_min_variation_price
_europe_min_variation_price
_united-kingdom_min_variation_price

We therefore just need the function to bring in the min-price only, for the user's currency instead of the current formatting which brings the max-price too.

If we spend time trying to get the views-woo-price field to work, we will still be left with the problem of it showing only the GBP price, and not those for other currencies, won't we?

#476952

Minesh
Supporter

Languages: Anglais (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - you need to write custom shortcode to get price based on your country.

For example:

function get_price_based_on_country($atts) {
    $country= $atts["country"];
   $post_id =  $atts["post_id"];

$price = get_post_meta( $post_id, '_'.$country.'_min_variation_price', true );      
    return $price;
}
add_shortcode("price-by-country", "get_price_based_on_country");

Now - Call the funtion as:

[price-by-country country="usa" post_id="your-post-id"] 

You need to find a way to get current country dynamically.

See following example:
http://stackoverflow.com/questions/24863612/woocommerce-product-price-depending-on-country

#477313

Hi again Minesh...

OK - I found the answer. Adding the code specified on this page, to my functions.php did the trick - and now I don't need a conditional to look for the price according to whether its a variable product or not, [wpv-woo-product-price] works for both:

http://stackoverflow.com/questions/36888531/show-minimum-price-for-woocommerce-variable-products-version-2-5-5

Thanks for all your help to track down the solution.
Tim

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.