I'm trying to retrieve price value for first modifier (only) within entries tag. My code looks like

{if product_details:price_val!=0} {product_details:price_val} {if:else} {product_details:modifiers} {product_details:price_mod_val} {/product_details:modifiers} {/if}

but always it returns an empty value for first modifier.

Any clue hot to bite that?



Based on directions from Ian (thanks!) I have finally got solution to my question.

To obtain first price (or all) for product modifiers I have used code below:

<?php $prices = array(); ?>
 {exp:store:product entry_id="{entry_id}" disable_form="yes" disable_javascript="yes"}
            {if price_mod_val}<?php $prices[] = {price_mod_val}; ?> {/if}

and then Pinterest OpenGraph part:

<?php if(!empty($prices)) {?>
<meta property="og:price:amount" content="<?php $price = number_format($prices[0], 2, '.', ''); echo $price; ?>" />    
<?php }
else { ?>
<meta property="og:price:amount" content="{if product_details:price_val!=0}{product_details:price_val}{if:else}99.99{/if}" />
<?php } ?>

I have try to use jQuery change to replace selected option price, but this works only when a visitor pin from that particular selection, but doesn't work when Pinterest will crawl back for price change/update. At that point I have stick only to primary (landing) product option.


Stash version:

 {exp:stash:set_list name="price_list" parse_tags="yes" parse_depth="3" parse_conditionals="yes"}
 {exp:store:product entry_id="{entry_id}" disable_form="yes" disable_javascript="yes"}
            {if price_mod_val}{stash:item_price}{price_mod_val}{/stash:item_price}{/if}

and OpenGrap price for Stash version:

{if {exp:stash:not_empty name="price_list"}}
{exp:stash:get_list name="price_list" limit="1" parse_tags="yes" parse_conditionals="yes"}
<meta property="og:price:amount" content="{item_price}" />    
<meta property="og:price:amount" content="{product_details:price_val}" />
  • 1
    You got it. Although if you (or anyone else) wanted to do the same thing without enabling PHP in their templates then Stash is a good option to store and re-use a variable elsewhere in the template or in the session.
    – Ian
    Apr 4 '14 at 7:36
  • Totally forgot about Stash (I have used it across my site). Will check it and post update. Apr 4 '14 at 17:27

To pull out the price for a modifier you should just need to do something like this:

        {if price_mod_val} ({price_mod}) {/if}

This will usually be done inside a select box for allowing a selection of each modifier option but above I've just stripped out all the HTML to place emphases on the Store tags only.

{price_mod} is the one which displays the price and {if price_mod_val} checks if it has a price to show

  • This is not working within entries loop tag (I have mentioned that in OP) and I need to retrieve only first price_mod_val. Your example is good when you do all modifiers selectors within store loop tag. Apr 2 '14 at 14:43
  • You wont be able to access modifier values without using Store tags but Store tags can sit within you EE channel entries loop. Use the {modifiers} tag pair if using the Product tag or {items} tag pair if using Checkout or Order tags.
    – Ian
    Apr 2 '14 at 18:32
  • Well, my goal is to get price passed to OpenGraph for Pinterest. As OpenGraph works only with 1 product option it requires to get that from first price_mod_val Apr 3 '14 at 15:21
  • No problem in using price_mod_val but you just need to wrap it in Store tags. If you need it elsewhere just save it as a session variable and call it out when and where needed.
    – Ian
    Apr 3 '14 at 18:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.