What do you do if the wordpress e-commerce (wp-ecommerce) buy now shortcode doesn’t work? In WP-ecommerce you can add a shortcode to allow customers to buy your product from any post or page by entering a shortcode like this:

[buy_now_button=3]

What if nothing displays?

First make sure you are placing the shortcode in HTML view instead of Visual view. Newer versions of Wordpress should support either, but if they don’t this can help.

Second, make sure you have Paypal as a payment method.

If you don’t want to support Paypal then you’ll need to do some quick coding to support the buy now feature without Paypal.

You’ll need to use an HTML editor like Dreamweaver or a text editor like BBEdit, Notepad, etc. and edit the WP-ecommerce plugin code file product_display_functions.php. In this file edit the function wpsc_buy_now_button.

To link to the product page update it like this:

function wpsc_buy_now_button($product_id, $replaced_shortcode = false) {
  global $wpdb;
  $selected_gateways = get_option('custom_gateway_options');
  $output = '';
  if (in_array('google', (array)$selected_gateways)) {
		$output .= google_buynow($product['id']);
	} else if (in_array('paypal_multiple', (array)$selected_gateways)) {
		if ($product_id > 0){
			$product_sql = "SELECT * FROM ".$wpdb->prefix."product_list WHERE id = ".$product_id." LIMIT 1";
			$product = $wpdb->get_row($product_sql, ARRAY_A);
			$output .= "
"; } } else { $output = ""; } if($replaced_shortcode == true) { return $output; } else { echo $output; } }

To have it add the item to the shopping cart and look like this

WP-Ecommerce Buy Now Button

WP-Ecommerce Buy Now Button

Modify the code as follows:

function wpsc_buy_now_button($product_id, $replaced_shortcode = false) {
  global $wpdb;
  $selected_gateways = get_option('custom_gateway_options');
  $output = '';
  if (in_array('google', (array)$selected_gateways)) {
		$output .= google_buynow($product['id']);
	} else if (in_array('paypal_multiple', (array)$selected_gateways)) {
		if ($product_id > 0){
			$product_sql = "SELECT * FROM ".$wpdb->prefix."product_list WHERE id = ".$product_id." LIMIT 1";
			$product = $wpdb->get_row($product_sql, ARRAY_A);
			$tax_percentage = 0;
			$country_data = $wpdb->get_row("SELECT * FROM `".$wpdb->prefix."currency_list` WHERE `isocode` IN('".get_option('base_country')."') LIMIT 1",ARRAY_A);
			if(($country_data['has_regions'] == 1)) {
				$region_data = $wpdb->get_row("SELECT `".$wpdb->prefix."region_tax`.* FROM `".$wpdb->prefix."region_tax` WHERE `".$wpdb->prefix."region_tax`.`country_id` IN('".$country_data['id']."') AND `".$wpdb->prefix."region_tax`.`id` IN('".get_option('base_region')."') ",ARRAY_A) ;
				$tax_percentage =  $region_data['tax'];
		}

			if($product['special']==1) {
				$price = $product['price'] - $product['special_price'];
	}

			$price += $tax_percentage;

			$output .= "
\n\r"; } } if($replaced_shortcode == true) { return $output; } else { echo $output; } }

Update: Use the code in this text file instead (product_display_functions.txt).

You may find the following resources helpful:

Hope this helps. If you have any questions or get stuck feel free to leave a question in the comments section below.