The New WP e-Commerce List Products and Images Hack

This post was moved to http://www.wpworking.com/hacks-2/the-new-wp-e-commerce-list-products-and-images-hack/


Well, this code bellow is what I call a “Chewbacca” code, but it works.

I present you the new hack to list products data and images where you want on your theme, if you are working with WP-ecommerce on WordPress.

It was tested on 3.8.5 version, and worked like a charm. If you are using older versions, check the old hack.

Also check WP e-Commerce Product Showroom 2.0.0 on the plugin menu.

$conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
mysql_select_db(DB_NAME) or die ("Could not select database, check you wp-config file" . mysql_error());
// if you are note sure about the value of $wp_table_prefix, perform a search for this
// text on your site, the usual value is "wp_" or something
$sql = "select pt.ID, pt.post_title from wp_posts As pt  ";
$sql .= "LEFT JOIN wp_postmeta As mt ON pt.ID=mt.post_id  ";
$sql .= "WHERE pt.post_type = 'wpsc-product' ";
$sql .= "AND pt.post_status = 'publish' ";
$sql .= "GROUP BY mt.post_id ";
$sql .= "ORDER BY pt.post_title ";
$sql .= "LIMIT 3 ";
$qry = mysql_query($sql);
$nrt = mysql_num_rows($qry);
while($rs = mysql_fetch_array($qry)):
//
$sqlp = "select meta_value from wp_postmeta as wm, wp_posts wp ";
$sqlp .= "where wm.meta_key='_wpsc_price' and wm.post_id=".$rs[0];
$sqlp .= " GROUP BY wm.post_id";
$qryp = mysql_query($sqlp);
while($rsp = mysql_fetch_array($qryp)):
	$prc = $rsp[0];
endwhile;
//
$sqli = "select meta_value from wp_postmeta as wm, wp_posts wp ";
$sqli .= "where wm.meta_key='_thumbnail_id' and wm.post_id=".$rs[0];
$sqli .= " GROUP BY wm.post_id";
$qryi = mysql_query($sqli);
while($rsi = mysql_fetch_array($qryi)):
	//
	$sqlt = "select guid from wp_posts where ID=".$rsi[0];
	$qryt = mysql_query($sqlt);
	while($rst = mysql_fetch_array($qryt)):
		$pht = $rst[0];
	endwhile;
endwhile;


$htmlcod .= "<div class='showrpdiv'>\n";
$htmlcod .= "<ul>\n";
$htmlcod .= "<li><a href=".wpsc_product_url($rs[0]).">".$rs[1]."</a><br>";
$htmlcod .= "<a href='".wpsc_product_url($rs[0])."'>";
$htmlcod .= "<img src='".$pht."' style='width:".$tbwid."px'></a>\n";
$htmlcod .= "</li>\n";
$htmlcod .= "<li>".$prc."</li>\n";                   
$htmlcod .= "</ul>\n";
$htmlcod .= "</div>\n";

endwhile;

echo $htmlcod;
  1. #1 by Mohamed on August 17, 2011 - 2:54 pm

    Hi man, thx for this hack i was looking for it been a while now. When do i have to put this code?

    • #2 by Alvaro Neto on August 17, 2011 - 3:02 pm

      Hi Mohamed, you can put this code anywhere you want on your theme pages. I recommend you take a look on my plugin WP e-Commerce Product Showroom, then you can use something like this hack as a widget.

      • #3 by Mohamed on August 17, 2011 - 3:12 pm

        Thank you,

        sure i’ll give it a shot 🙂

  2. #4 by Alvaro Neto on August 24, 2011 - 9:25 pm

    Hi Xavier, try using this hack. If it doesn’t work, I can send you a free price quote for the specific service of making it work, if desired. Good luck, best regards.

  3. #5 by Xavier on August 25, 2011 - 12:32 pm

    Alvaro thanks for the information one question. When implementing this where is is db user, db psw etc do I need to put my sql information there? Also with the second image hack. Where do this need to be pasted to.

    Thank you for your time.

    • #6 by Alvaro Neto on August 25, 2011 - 12:46 pm

      Xavier, on my code I’m using WordPress globals, but sure you can use your database information. Best regards.

  4. #7 by Xavier on August 25, 2011 - 12:58 pm

    It worked thank you so much. Man your smart is this all you do?

    • #8 by Alvaro Neto on August 25, 2011 - 1:08 pm

      Nice Xavier, I’m very happy to know it works. You can buy me a beer if you want, to support my hardworking, but most of all I’m glad you are using the codes of my site.

  5. #9 by Andi on September 7, 2011 - 7:58 pm

    you are so cool mate! thanks a lot for the hack! but my thumbimages get not listed. using the latest version of wpec. did they already change something ?

    • #10 by Alvaro Neto on September 8, 2011 - 12:22 am

      Thanks for your comment Andy. First I have to tell the new blog url: http://wpworking.com You should check your database tables sufix. The code was made to work with the default prefix “wp_”. Also, check if all products has a image attached. Please let me know if it works, stay in touch using directly my email alvaron8@gmail.com.

  1. WP e-Commerce List Products and Images Hack « It works on WordPress

Leave a comment