• Resolved toolsavvy

    (@toolsavvy)


    So I have a price comparison site. NO, IT IS NOT BUILT WITH WOOCOMMERCE. The price for each product is set in the back end using a “Price field”. Then that price is shown on the front end for each product using a shortcode [price].

    Is there anyway to get this plugin to work with this kind of setup?

    I tried using Outerbridge Nested Shortcodes plugin to nest my price shortcode with your [wpcs_price value=] shortcode, but that does not seem to work. However, I may be doing it wrong.

    I have a feeling you woocommerce plugin is doing what I need, but I tried installing that and it seems it only works if you have woocommerce installed so that will not work for me.

    Please let me know if there is away to do this with your plugin.

Viewing 9 replies - 1 through 9 (of 9 total)
  • Thread Starter toolsavvy

    (@toolsavvy)

    I actually figured this out, I think. It involves using the PHP Code For Posts plugin and a bit of PHP code using the do_shortcode function to make your own shortcode to replace the [wpcs_price value=] shortcode. Well, you’re not replacing it but rather placing it in the PHP code then calling it with your new shortcode. It’s actually quite easy and NO theme or plugin modification is required!

    I will post the total solution once I have tested it out thoroughly to make sure everything is working properly and currencies are converting properly. So far, so good!

    If everything tests out properly, I will be buying the paid version for sure!!! Well worth it for me.

    • This reply was modified 8 years ago by toolsavvy.
    pavloborysenko

    (@pavloborysenko)

    Hello

    Thank you for cooperation!

    Thread Starter toolsavvy

    (@toolsavvy)

    So here’s how I did it for my theme. I presume that this may work for most themes, but no guarantee.

    You will need 2 plugins. This one and the “PHP Code For Posts” plugin. That that plugin does is it allows you to turn snippets of PHP code or really any code into a shortcode.

    So, once you’ve installed that plugin, go in and make a snippet/shortcode using the following code…

    <?php
       $price = get_post_meta($postid = get_the_ID(), 'price', true);
       $number = money_format('%.2n', $price);
    ?>
    
    <span class="wlt_shortcode_price"><?php echo do_shortcode( "[wpcs_price value='$number']" );?></span>

    – where “$price” and ” ‘price’ ” are whatever variable your theme uses as the price variable for your products. My theme happens to use “$price”.
    – where wlt_shortcode_price is the css class for your price field on your theme.

    Save that snippet/shortcode. Now you should have a snippet/shortcode called [php snippet=1]

    Install the WP currency Switcher plugin and set up your currencies how you want them and place the [wpcs show_flags=0 width=’300px’ txt_type=’desc’] shortcode of the plugin where ever you want it to appear on your site.

    Then, wherever your price shortcode appears in your code for your theme, replace that with the [php snippet=1] shortcode you just made and voila, your prices will now be controlled by currency switcher.

    It works great for me on my theme. The only thing to note is that it will not add a thousands separator to your prices so if you have high priced items them this may bother you. I have tried many variations of PHP does to place the thousands separator in the price and I cannot figure it out. You can’t use the setlocale(LC_MONETARY, 'en_US') code but that messes up WP Currency Switcher. You have to let WP Currency switcher dictate the local money format, not the php code of the theme.

    pavloborysenko

    (@pavloborysenko)

    Hello

    In file \wp-content\plugins\currency-switcher\index.php paste this code( https://c2n.me/3HNIIZc.png ) :

    ` if(is_array($value)){
    $key.=”[]”;
    $value= implode(“,”, $value);
    }`

    Do test!

    Thread Starter toolsavvy

    (@toolsavvy)

    pavloborysenko

    (@pavloborysenko)

    Hello
    Sorry!!! ??

    Plugin Author RealMag777

    (@realmag777)

    Thread Starter toolsavvy

    (@toolsavvy)

    Sorry it took so long to get back to you. I updated the plugin and tested the new meta field feature and it works fine in my theme. Thank you very much.

    And for those of you who need to use the new shortcode within your PHP code using the do_shortcode function, the syntax is

    do_shortcode( '[wpcs_price meta_value="YOUR PRICE META VALUE HERE"]' )

    in my case, my price meta value is simply “price” so my code would be…

    do_shortcode( '[wpcs_price meta_value="price"]' )

    Hello

    do_shortcode( ‘[wpcs_price meta_value=”price”]’ ) – Yes!

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Can this plugin convert price of a field?’ is closed to new replies.