New Min Price Fix – (To accept current amount)
-
Currently the plugin doesn’t allow minium price in the true sense of the word.
Example: If you set £25.00 as the minimum price, £25.00 is rejected and the user must enter at least £25.01. This is wrong… the minimum price is £25.00, not £25.01
My solution was to add the following code to the price.php file. It takes the price entered and simply take a penny / cent off the price.
<?php $newminimum = $product->get_price() ?> <?php $newminimum = ($newminimum - 0.01); ?> <input type="hidden" id="minimum_price" name="minimum_price" style="padding: 8px;" value="<?php echo $newminimum; ?>" />
It works and gives the actual desired effect.
https://www.ads-software.com/plugins/shatner-name-your-own-price-for-woocommerce/
-
Do I just add the code into /plugins/shatner-name-your-own-price-for-woocommerce/templates/single-product/price.php? Where should I add in? I tried adding at the bottom and it didn’t work.
Hi Peter!
Thanks for sharing this!Where can I find the file price.php?
I am trying to figure out how to set a minimum price that is different than the suggested price.
I sell an ebook, and the suggested price is USD 10. As I had some people choosing “0” as a price, and the book is not free, I want to stop that setting USD 2 as the minimum price, but the only way I noticed I could do it is by setting the suggested price into USD 2… and I want to keep it USD 10.
So, after reading your post, I though I could use this code like this:<?php $newminimum = $product->get_price() ?>
<?php $newminimum = ($newminimum – 8.01); ?><input type=”hidden” id=”minimum_price” name=”minimum_price” style=”padding: 8px;” value=”<?php echo $newminimum; ?>” />
Is this right?
If so, could you help me with more instructions on where I should put this code?THANKS SO MUCH!!!!!!!
I dropped my coded into: woocommerce/templates/single-product/price.php
I added in between the if statment enforce_minium. Adding it at the bottom wouldn’t work.
For your problem ‘marcandoelpolo’ I would put the minimum price in the backend to 2USD within the woocommerce product.
Don’t change my code, as this works for all currencies and will allow the user to put in 2USD
Then in the Code add an heading tag with a suggested price below the minimum price.
Here is my whole price.php file
<?php /** * Single Product Price, including microdata for SEO * * @author WooThemes / Sean Voss * @package Shatner/WooCommerce/Templates * @version 1.6.4 - Lolz */ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly global $post, $product; $own_price = get_post_meta($post->ID, '_own_price', true); $enforce_minimum = get_post_meta($post->ID, '_own_price_enforce_minimum', true); if($own_price == 'yes') { ?> <div itemprop="offers" itemscope itemtype="https://schema.org/Offer"> <div class="name_price"> <h5 itemprop="price" class="price">Minimum Price: <?php echo $product->get_price_html(); ?></h5> <p itemprop="name_price price" class="price" style="margin-top: 20px;"> <label><?php echo get_option('shatner_label', "Name your own price") ?> </label> <input name='price' class='name_price' type='text' /> <?php if ($enforce_minimum == 'yes') { ?> <?php $newminimum = $product->get_price() ?> <?php $newminimum = ($newminimum - 0.01); ?> <input type="hidden" id="minimum_price" name="minimum_price" style="padding: 8px;" value="<?php echo $newminimum; ?>" /> <?php } ?> </p> </div> <meta itemprop="priceCurrency" content="<?php echo get_woocommerce_currency(); ?>" /> <link itemprop="availability" href="https://schema.org/<?php echo $product->is_in_stock() ? 'InStock' : 'OutOfStock'; ?>" /> </div> <? } else { ?> <div itemprop="offers" itemscope itemtype="https://schema.org/Offer"> <p itemprop="price" class="price"><?php echo $product->get_price_html(); ?></p> <meta itemprop="priceCurrency" content="<?php echo get_woocommerce_currency(); ?>" /> <link itemprop="availability" href="https://schema.org/<?php echo $product->is_in_stock() ? 'InStock' : 'OutOfStock'; ?>" /> </div> <? } ?>
Thanks a lot, Peter!
I found the file ??
So the only thing I need to add is:<?php $newminimum = $product->get_price() ?>
<?php $newminimum = ($newminimum – 0.01); ?>
<input type=”hidden” id=”minimum_price” name=”minimum_price” style=”padding: 8px;” value=”<?php echo $newminimum; ?>” />
<?php } ?>Is that right?
Should I change ($newminimum – 0.01) into ($newminimum – 8.01) as my regular price is 10, and I want the minimun price to be 2.And last question, how would be the heading tag with a suggested price below the minimum price?
I am really sorry to bother you, but I am learning to code and many things are still too dificult for me!
Thanks a lot, I REALLY appreciate your help.Kind regards,
Daniela
Hi again, I read again and I understand what you mention, but the woocommerce product only allows me to choose the same minimun price as the suggested price, that′s why I was thinking of using thi code with the 8.01 discount.
I Personally would put the minium price of 2USD which would allow the user to enter 2USD.
Then with the Price.php simply change the code
<h5 itemprop="price" class="price">Minimum Price: <?php echo $product->get_price_html(); ?></h5>
With something similar to:
<h5 itemprop="price" class="price">Suggested Price: $10</h5>
It would appear that the price is $10 but still allow people to enter $2
Thanks!!! It worked!!!!!
I just use this code with 8.01 and worked perfectly!
THANKS HEAPS!!!!
To fix the greater-than minimum price error in Shatner Name Your Price, I used a quick fix in the
“/wp-content/plugins/shatner-name-your-own-price-for-woocommerce/shatner.js” file, as follows:Just below the opening jQuery statement:
jQuery(function($){ $('.cart').click(function(){
Add this chunk of code:
// Test to see if the price is exactly the minimum price (ie the Suggested Price): if($('#minimum_price').length && parseFloat($('#minimum_price').val()) == parseFloat($('input.name_price').val())) { return; }
So first we test if it’s Exactly the same, since the value test
>=
in the old version didn’t work for some reason.Now this allows the price/donation to be ok with prices that are Exactly the minimum stated in the “Suggested Price” label, making it less confusing for the end-user.
Might not be foolproof, but it was quick, and no php math mess and cents etc that may conflict/interact with other price-based plugins that may be installed.
Let me know if you have success guys!
Hello! How did work. = /
I think it’s because here in Brazil unused point “.” For decimal places, but the comma “,”
How to fix this?
Follow my code.
<?php /** * Single Product Price, including microdata for SEO * * @author WooThemes / Sean Voss * @package Shatner/WooCommerce/Templates * @version 1.6.4 - Lolz */ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly global $post, $product; $own_price = get_post_meta($post->ID, '_own_price', true); $enforce_minimum = get_post_meta($post->ID, '_own_price_enforce_minimum', true); if($own_price == 'yes') { ?> <div itemprop="offers" itemscope itemtype="https://schema.org/Offer"> <div class="name_price"> <p itemprop="name_price price" class="price"> <label><?php echo get_option('shatner_label', "Name your own price") ?> </label> <input name='price' class='name_price' type='text' /> <h6 itemprop="price" class="price">Pre?o Mínimo: <?php echo $product->get_price_html(); ?></h6> <?php if ($enforce_minimum == 'yes') { ?> <?php $newminimum = $product->get_price() ?> <?php $newminimum = ($newminimum - 0.01); ?> <input type="hidden" id="minimum_price" name="minimum_price" style="padding: 8px;" value="<?php echo $newminimum; ?>" /> <input type="hidden" id="minimum_price" name="minimum_price" value=" <?php echo $product->get_price() ?>" /> <?php } ?> </p> </div> <meta itemprop="priceCurrency" content="<?php echo get_woocommerce_currency(); ?>" /> <link itemprop="availability" href="https://schema.org/<?php echo $product->is_in_stock() ? 'InStock' : 'OutOfStock'; ?>" /> </div> <? } else { ?> <div itemprop="offers" itemscope itemtype="https://schema.org/Offer"> <p itemprop="price" class="price"><?php echo $product->get_price_html(); ?></p> <meta itemprop="priceCurrency" content="<?php echo get_woocommerce_currency(); ?>" /> <link itemprop="availability" href="https://schema.org/<?php echo $product->is_in_stock() ? 'InStock' : 'OutOfStock'; ?>" /> </div> <? } ?>
If anyone can help me I will be forever grateful!
=D
Sorry for the spam, but:
I followed the instructions in this post:
https://www.ads-software.com/support/topic/commas-instead-of-dot?replies=4But not work.
Thanks!
Thiago
- The topic ‘New Min Price Fix – (To accept current amount)’ is closed to new replies.