You are here:  » How to view lowest price on wordpress widgets


How to view lowest price on wordpress widgets

Submitted by elior99 on Mon, 2016-12-19 12:54 in

Hi,
I'm looking for a way to use some shortcode or other code to view only lowest price by name.
I have viausl composer sidebar and it takes my top/latest post and i want to add the lowest price to each one.

If it's not possbile i would like to know how to show in search results only posts/pages that include price comparison and not all imported items.

Thank you!

Submitted by support on Mon, 2016-12-19 13:24

Hello Elior and welcome to the forum!

To add a [pto lowest="Product Name"] shortcode, edit the plugin file pto.php and look for the following code at line 450:

        case "search":

...and REPLACE with:

        case "lowest":
          global $config_currencyHTML;
          $sql = "SELECT price FROM `".$pto_config_databaseTablePrefix."products`
                    WHERE name = '".$wpdb->escape($v)."' ORDER BY price LIMIT 1";
          if ($wpdb->query($sql))
          {
            $html .= $config_currencyHTML.$row->price;
          }
          break;
        case "search":

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by elior99 on Mon, 2016-12-19 13:57

Thanks David.
I'm getting table for some reason and not the price only.

Submitted by support on Mon, 2016-12-19 14:03

Hi,

Sorry about that - I missed out the break statement in the replacement - corrected above, and then double check that you are using lowest instead of prices shortcode e.g.

[pto lowest="Product Name"]

Cheers,
David.
--
PriceTapestry.com

Submitted by knhans on Tue, 2017-07-11 09:19

Hi there,

Sorry to break into this one, but i want to do the same for some extra fields which i created in the database. The extra fields are per_stuk (price a piece) and soort (subname).

I try to do the following:

case "lowest":
          global $config_currencyHTML;
          $sql = "SELECT per_stuk FROM `".$pto_config_databaseTablePrefix."products`
                    WHERE soort = '".$wpdb->escape($v)."' ORDER BY per_stuk LIMIT 1";
          if ($wpdb->query($sql))
          {
            $html .= $config_currencyHTML.$row->price;
          }
          break;
        case "search"

And the shortcode: [pto lowest="Soort Name"]
If i try a query in my database it works fine:
SELECT per_stuk FROM `pt_products` WHERE soort = 'DryNites' ORDER BY price Limit 1

Thanx in advance!

Submitted by support on Tue, 2017-07-11 10:49

Hello knhans,

Although you're SELECT'ing per_stuk the display code is still using price - so this line;

             $html .= $config_currencyHTML.$row->price;

...should be:

             $html .= $config_currencyHTML.$row->per_stuk;

...that should be all it is...

Cheers,
David.
--
PriceTapestry.com

Submitted by knhans on Wed, 2017-07-12 12:23

Hmm i had it like that, guess i copied the wrong code in here.
But iam still dont get anything, do you have any other suggestions?

Submitted by support on Wed, 2017-07-12 12:47

Hi,

Sorry about that - have a go with the following replacement - the above code wasn't using the return variable of $wpdb but this should do the trick;

case "lowest":
          global $pto_config_currencyHTML;
          $sql = "SELECT per_stuk FROM `".$pto_config_databaseTablePrefix."products`
                    WHERE soort = '".esc_sql($v)."' ORDER BY per_stuk LIMIT 1";
          if ($wpdb->query($sql))
          {
            $html .= $pto_config_currencyHTML.$wpdb->last_result[0]->per_stuk;
          }
          break;
        case "search"

(also updated to esc_sql() from deprecated $wpdb->escape()...)

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by knhans on Wed, 2017-07-12 14:45

Ah super thank you!

its missing a : in the end but it working now!

case "lowest":
          global $pto_config_currencyHTML;
          $sql = "SELECT per_stuk FROM `".$pto_config_databaseTablePrefix."products`
                    WHERE soort = '".esc_sql($v)."' ORDER BY per_stuk LIMIT 1";
          if ($wpdb->query($sql))
          {
            $html .= $pto_config_currencyHTML.$wpdb->last_result[0]->per_stuk;
          }
          break;
        case "search":