• Resolved szmery

    (@szmery)


    Hi
    First at all – thanks for great tool!

    I need to use commas instead of dots when someone offers his price. I know that WP/Woocommerce use dots and commas are for display purposes only. So i figured out that the simplest way to achieve my goal is to pass the $price value trough eregi_replace function but i’m not sure where should this be done.
    Could you help me with this one?

    Thanks,
    Have a nice day,
    Bartek

    https://wordpress.org/plugins/shatner-name-your-own-price-for-woocommerce/

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter szmery

    (@szmery)

    Ok, i get it 😉

    in case if someone need this:
    shatner.js needed to replace value of hidden #minimum_price object with:
    .replace(“.”, “,”);

    Thread Starter szmery

    (@szmery)

    OK, actually, this wasn’t correct, however i’ve found working solution.

    In the beggining of shatner.js find this:

    // Test to see if the price exceeds the minimum price (ie the Suggested Price):
    
    	if($('#minimum_price').length && parseFloat($('#minimum_price').val()) >= parseFloat($('input.name_price').val()))

    and replace by this:

    // Test to see if the price exceeds the minimum price (ie the Suggested Price):
    
    	var minimum = $('#minimum_price').val();
    	var myprice = $('input.name_price').val();
    	myprice = myprice.replace(",", ".");
    
        if(parseFloat(minimum) > parseFloat(myprice))

    This one solves two problems:
    – lets users input prices with commas instead of dots
    – lets user input price exact as the minimum

    Hello!

    You could set the minimum price? I made this change, but is passing normally.

    =/

    Thiago

    Thread Starter szmery

    (@szmery)

    Hello

    Please, see the screenshot from WooCommerce product page.

    Hello,

    http://prntscr.com/78246r

    Thanks for help.

    Thiago

    But im using this code in price.php

    <?php $newminimum = $product->get_price() ?>
    <?php $newminimum = ($newminimum - 0.01); ?>

    And this code in shatner.js

    var minimum = $('#minimum_price').val();
    var myprice = $('input.name_price').val();
    myprice = myprice.replace(",", ".");


    Result:

    http://prntscr.com/78271f

    Thanks for help again! =)

    Thread Starter szmery

    (@szmery)

    Honestly, it was 7 months ago and i’m not sure if i remember exactly all i have done.
    All i can do is to look into my code; maybe it could help you.

    First at all – i’m not sure which version of WooCommerce you’re working on. Mine is older, 2.2.0 if i remember.

    Anyway – i haven’t change anything on price.php:

    if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
    global $product;
    
    <?php if ( $price_html = $product->get_price_html() ) : ?>
    	<span class="price"><?php echo $price_html; ?></span>
    <?php endif; ?>

    And i’m not sure why you use this:
    $newminimum = ($newminimum - 0.01)
    – and why you define $newminimum anyway?
    Maybe that’s your problem? Do you use it somewhere else?

    Here’s content of my shatner.js:

    jQuery(function($){
      $('.cart').click(function(){
    
    // Test to see if the price exceeds the minimum price (ie the Suggested Price):
    
    	var minimum = $('#minimum_price').val();
    	var myprice = $('input.name_price').val();
    	myprice = myprice.replace(",", ".");
    
        if(parseFloat(minimum) > parseFloat(myprice))
    
        {
            alert('Please offer a price higher than the Minimum Price.');
            return false;
        } 
    
    // See if the price input is zero (because we want people to be able to choose a free option: NEEDS LOGIC FOR SET MINIMUM
    
        else if(parseFloat($('input.name_price').val()) == 0)
        {
            return;
        }  
    
    // Test to see if the input field has been left blank:
    
        else if($('.name_price').length && !parseFloat($('input.name_price').val()))
        {
            alert('Please enter a price in the Price field!');
            return false;
        }
    
    // Test to see if input field is non-negative:
    
        else if(parseFloat($('input.name_price').val()) < 0)
        {
            alert("Look here, old chap, that's just not on. Please enter a positive number, or zero. Tsk tsk.");
            return false;
        }
    
      });
      $('.cart').submit(function(){
    
        $('<input name="price" />').val($('input.name_price').val()).attr('type','hidden').appendTo($('form.cart'));
        return;
      });
    });

    Good luck 😉

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Commas instead of dots’ is closed to new replies.