You are here:  » shortcode for sku


shortcode for sku

Submitted by henk on Sun, 2012-10-14 12:51 in

Hi David,

How can i make a shortcode for sku?

[pto product="sku:123456" prices="sku:123456"]

Thx
Henk

Submitted by support on Mon, 2012-10-15 08:18

Hello Henk,

In your modified pto_product.php, look for the following code beginning at line 282:

  $sql = "SELECT * FROM `".$pto_config_databaseTablePrefix."products` WHERE normalised_name = '".$wpdb->escape($pto_product)."' LIMIT 1";
  if ($numRows = $wpdb->query($sql))

...and REPLACE with:

  $sql = "SELECT * FROM `".$pto_config_databaseTablePrefix."products` WHERE normalised_name = '".$wpdb->escape($pto_product)."' LIMIT 1";
  $parts = explode(":",$pto_product);
  if ($parts[0]=="sku")
  {
    $sql = "SELECT * FROM `".$pto_config_databaseTablePrefix."products` WHERE sku = '".$wpdb->escape($parts[1])."' ORDER BY price";
    $numRows = $wpdb->query($sql);
    $product = $wpdb->last_result[0];
  }
  elseif ($numRows = $wpdb->query($sql))

Cheers,
David.
--
PriceTapestry.com

Submitted by henk on Mon, 2012-10-15 19:49

Hi David,

Sorry it doesn't show by sku only still by name when i try [pto product="sku:4008146387401"]

Thx
Henk

Submitted by support on Tue, 2012-10-16 08:53

Hello Henk,

Ah - that's because ":" is removed by the normalisation; to allow this, perform a Search and Replace in pto.php of

$pto_product = pto_common_normalise($v);

with:

$pto_product = pto_common_normalise($v,":");

(4 instances)

You will then have support for sku:n for product, prices, reviews and search short codes.

Cheers,
David.
--
PriceTapestry.com

Submitted by henk on Tue, 2012-10-16 14:54

Great,

Thx
Henk