Fixing the “Warning: array_merge() [function.array-merge]:” error in WordPress’s WP-Ecommerce plugin

When I first installed the WP-Ecommerce plugin on a website this morning and tried to go to the products page, I got this error:

<strong>Warning</strong>: array_merge() [function.array-merge]: Argument #1 is not an array in <strong>/public_html/wp-content/plugins/wp-e-commerce/wpsc-core/wpsc-functions.php</strong> on line <strong>622</strong>

Thankfully, it is actually very easy to fix this error. All you need to do is add (array) to the correct line of code in the plugin’s functions.php file.

Find this line in your wp-e-commerce/wpsc-core/wpsc-functions.php file:

$args = array_merge($wp_query->query, array('posts_per_page' => get_option('wpsc_products_per_page')));

And change it to this:

$args = array_merge((array)$wp_query->query, array('posts_per_page' => get_option('wpsc_products_per_page')));

 

That did the trick for me and hopefully will work for you too. Let me know if you have any questions or run into issues with this.

Use a dropdown menu to apply a discount to your PayPal button

Using a dropdown menu rather than a text box to apply different discounts to your PayPal button is actually very simple.
All you need to do is change this code:

<input type = "text" size = "10" name = "coupcode"; />

to this:

 <select name= "coupcode";>
 <option value="coupl"> Friend
 <option value="coup2" > Online
 <option value="coup3">Other
 </select>

You can see a working example of this at http://icode4you.net/wp-content/uploads/2011/11/coupon.html.

How to make your PayPal button open in a new window

Add this line of code to your PayPal button code to make it open in a new window when clicked:

target="_blank"

You would add this to the

section of the button code:

<form target="_blank" action="<a href="https://www.paypal.com/cgi-bin/webscr" rel="nofollow" target="_blank">https://www.paypal.com/cgi-bin/webscr</a> method="post">

Create a discount or coupon for a set dollar amount for a PayPal button

Here are the codes you can use to create a coupon or discount for a set dollar amount for your PayPal buttons (as opposed to a percentage amount, which I covered in a previous post on how to create a coupon for your PayPal button).

First, use this code for your button:

<form action="https://www.paypal.com/cgi-bin/webscr" method="post" onsubmit="this.target = 'paypal'; return ReadForm (this);">
<input type="hidden" name="cmd" value="_xclick" />
<input type="hidden" name="add" value="1" />
<input type="hidden" name="business" value="" />
<input type="hidden" name="item_name" value="10 sessions" />
<input type="hidden" name="amount" value="773.00" />
<input type="hidden" name="currency_code" value="USD" />
<input type="hidden" name="baseamt" value="773.00" />
<input type="hidden" name="basedes" value="10 sessions" />
Enter Coupon code
<input type     = "text" size     = "10"  name     = "coupcode"; />
<input type="button" value="Check code" onclick="coupval =this.form.coupcode.value;  ChkCoup();" /><br/><br/>
<input type="image" id="xx" disabled="disabled" src="https://www.paypalobjects.com/WEBSCR-640-20110306-1/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" onclick="CalculateOrder(this.form)" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypalobjects.com/WEBSCR-640-20110306-1/en_US/i/scr/pixel.gif" width="1" height="1">
</form>

Make sure you use either your PayPal email address or your Merchant account ID number for this line:

<input type="hidden" name="business" value="" />

Next, we will create the Javascript file we need. Here is the code I use:

<!--
var discnt = 0;   // no default percent discount

var coupons = new Array (  // place to put coupon codes
  "coup1",                 // 1st coupon value - comma seperated
  "coup2",                 // 2nd coupon value - add all you want
  "coup3"                  // 3rd coupon value
);
var coupdc  = new Array (  // place to put discounts for coupon vals
  5,
  10,
  15
);
var coupval = "(blanket)"; // what user entered as coupon code

function ChkCoup () {      // check user coupon entry
var i;
  discnt = 0;              // assume the worst
  for (i=0; i<coupons.length; i++) {
    if (coupval == coupons[i]) {
      discnt = coupdc[i];  // remember the discount amt
      alert ("This is a valid promo code! \n\n" + "$" + discnt +
             " discount now in effect.");
      return;
    }
  }
  alert ("'" + coupval + "'  is not a valid promo code!");
}

function Dollar (val) {      // force to valid dollar amount
var str,pos,rnd=0;
  if (val < .995) rnd = 1;  // for old Netscape browsers
  str = escape (val*1.0 + 0.005001 + rnd);  // float, round, escape
  pos = str.indexOf (".");
  if (pos > 0) str = str.substring (rnd, pos + 3);
  return str;
}

function ReadForm (obj1) {  // apply the discount
var amt,des;
  amt = obj1.baseamt.value*1.0;       // base amount
  des = obj1.basedes.value;           // base description

  if (discnt > 0) {                   // only if discount is active
    amt = Dollar (amt - (discnt));
    des = des + ", " + "$" + discnt + "dis, COUP = " + coupval;
  }

  obj1.amount.value = Dollar (amt);
  obj1.item_name.value = des;
}
//-->

Here is a link to the Javascript file that you need – http://thelibzter.com/discount2.js. Feel free to right-click and save that file to your computer rather than creating your own Javascript file if you wish.

To add the passwords you want to use, change the names coup1coup2, and coup3 to the passwords that you want to use.

To add the discount amounts, change the 510, and 15 to the percentage that you want the discounts to be for.

The final step, which I use to make the discount button more secure, is to pack part of the Javascript code. I copy the line of the code that contains my discount passwords:

var coupons = <strong>new</strong> Array (  // place to put coupon codes   "coup1",                 // 1st coupon value - comma seperated   "coup2",                 // 2nd coupon value - add all you want   "coup3"                  // 3rd coupon value );

And paste it into Dean Edward’s packer – http://dean.edwards.name/packer/. Click “pack” and then copy the packed code and paste it into your Javascript file in place of the line above, which declared our passwords. This makes it more difficult for people to see your passwords.

Save the Javascript file as discount.js or whatever you want it to be called. Upload it to your server. Add this line of code to your website’s section:

<script type="text/javascript" src="http://yourwebsite.com/discount.js"></script>

Make sure you change the name of the Javascript file in the code above to the name of your own file.

How to sell affiliate products in your Interspire Shopping Cart store

Here is the simple way I have found to sell affiliate products in your Interspire Shopping Cart store.

First, get the code that your affiliate provides you to add the affiliate products to your website.

Next, go to Add a Product in your Interspire admin panel.

Click the “HTML” button above the box where you type in the product description:

Paste the code from your affiliate into the window that pops up.

Scroll down in the pop up window and click the “Update” button.

You should now see the affiliate product in the Product Description box.

If there is an image for the product, right-click it and save it to your computer. Then delete it from the Product Description and add the image as you would add an image to any other product in your store.

Copy and paste the product name into the correct field, put the product in the correct category on your site, and add the price to the correct field.

Once you have the product listed the way you want, scroll down and UN-check the box next to “Allow customers to purchase this item.”

Save the product and go look at in in your store. It should look just like any other product you would add to the store, except that in order to purchase it, people have to click the affiliate link which you pasted into the product description (this way their clicks from your website to the affiliate site will be tracked, since you are using the code that the affiliate site gave you).

Let me know if you have any issues with this or any questions about it.

How to create a coupon discount for PayPal buttons

Here are the codes I use to create a coupon discount for PayPal buttons.

First, create your PayPal button:

  1. Log in to your PayPal account.
  2. Click on the Merchant Services Tab and select “Buy Now Button”
  3. Click create a “Buy Now” button.
  4. Enter your information to customize the button to your needs.
  5. Click Step 2 and uncheck the “Save button at PayPal”
  6. Click “Create Button.”
  7. Click “Remove code protection”
  8. Click “Select Code” to select the button code.

Next, paste the code for your PayPal button into your webpage.

To add the check discount code box, paste this line of code before the “input type=”image” part of the button code:

Enter Coupon code
<input type="text" size="10" name="coupcode"; />
<input type="button" value="Check code" onclick="coupval =this.form.coupcode.value;  ChkCoup();" />

You can also use this block of code for your button and edit as needed rather than generating your own button from PayPal:

<form action="https://www.paypal.com/cgi-bin/webscr" method="post" onsubmit="this.target = 'paypal'; return ReadForm (this);">
<input type="hidden" name="cmd" value="_xclick" />
<input type="hidden" name="add" value="1" />
<input type="hidden" name="business" value="" />
<input type="hidden" name="item_name" value="1 Item" />
<input type="hidden" name="amount" value="50.00" />
<input type="hidden" name="currency_code" value="USD" />
<input type="hidden" name="baseamt" value="50.00" />
<input type="hidden" name="basedes" value="1 Item" />
Enter Coupon code
<input type="text" size="10" name="coupcode"; />
<input type="button" value="Check code" onclick="coupval =this.form.coupcode.value;  ChkCoup();" />
<input type="image" id="xx" src="https://www.paypalobjects.com/WEBSCR-640-20110306-1/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" onclick="CalculateOrder(this.form)" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypalobjects.com/WEBSCR-640-20110306-1/en_US/i/scr/pixel.gif" width="1" height="1">
</form>

Make sure you add the correct value (either your PayPal email address or your Merchant account ID number) to this line:

<input type="hidden" name="business" value="" />

If you want to force people to use a discount code before adding an item to their cart, make sure you add this line of code to the disabled="disabled"

This disables the button until the correct coupon code is entered. This is only necessary if you are using the button ONLY for people who have discount codes. If you want people to be able to make purchases whether they have a discount code or not, you don’t need to add that line.

Next, you will want to create the Javascript file which contains the passwords and discounts for your button. Copy and paste this code into a new text file:

<!--
var discnt = 0;   // no default percent discount

var coupons = new Array (  // place to put coupon codes
  "coup1",                 // 1st coupon value - comma seperated
  "coup2",                 // 2nd coupon value - add all you want
  "coup3"                  // 3rd coupon value
);
var coupdc  = new Array (  // place to put discounts for coupon vals
  5,
  10,
  15
);
var coupval = "(blanket)"; // what user entered as coupon code

function ChkCoup () {      // check user coupon entry
var i;
  discnt = 0;              // assume the worst
  for (i=0; i<coupons.length; i++) {
    if (coupval == coupons[i]) {
      discnt = coupdc[i];  // remember the discount amt
      alert ("This is a valid promo code! \n\n" + discnt + "%" + 
             " discount now in effect.");
      return;
    }
  }
  alert ("'" + coupval + "'  is not a valid promo code!");
}

function Dollar (val) {      // force to valid dollar amount
var str,pos,rnd=0;
  if (val < .995) rnd = 1;  // for old Netscape browsers
  str = escape (val*1.0 + 0.005001 + rnd);  // float, round, escape
  pos = str.indexOf (".");
  if (pos > 0) str = str.substring (rnd, pos + 3);
  return str;
}

function ReadForm (obj1) {  // apply the discount
var amt,des;
  amt = obj1.baseamt.value*1.0;       // base amount
  des = obj1.basedes.value;           // base description

  if (discnt > 0) {                   // only if discount is active
    amt = Dollar (amt - (amt * discnt/100.0));
    des = des + ", " + discnt + "%" + "dis, COUP = " + coupval;
  }

  obj1.amount.value = Dollar (amt);
  obj1.item_name.value = des;
}
//-->

Here is a link to the Javascript file that you will need – http://thelibzter.com/discount.js. Feel free to right-click and save the file to your desktop so that you can edit it and upload it to your own site.

To add the coupon codes you want to use, change the names coup1, coup2, and coup3 to the passwords that you want to use.

To add the discount amounts, change the 5, 10, and 15 to the percentage that you want the discounts to be for.

You will want to make sure that the button amount is higher than any of the discounted prices. For instance, if you want to offer three different discounts – one which reduces the price to $750, one which reduces is to $725, and one which reduces it to $700 – you will want to make sure that the amount of the original button is at least $750, and then add the discounts for the correct percentages to bring the price down to the amount you want.

The final step, which I use to make the discount button more secure, is to pack part of the Javascript code. I copy the line of the code that contains my discount passwords:

var coupons = <strong>new</strong> Array (  // place to put coupon codes   "coup1",                 // 1st coupon value - comma seperated   "coup2",                 // 2nd coupon value - add all you want   "coup3"                  // 3rd coupon value );

And paste it into Dean Edward’s packer – http://dean.edwards.name/packer/. Click “pack” and then copy the packed code and paste it into your Javascript file in place of the line above, which declared our passwords. This makes it more difficult for people to see your coupon codes.

Save the Javascript file as discount.js or whatever you want it to be called. Upload it to your server. Add this line of code to your website’s section:

<script type="text/javascript" src="http://yourwebsite.com/discount.js"></script>

Make sure you change the name of the Javascript file in the code above to the name of your own file.

Let me know if you run into any issues or have any questions.

Interspire Shopping Carts: Add a Flyout or Dropdown Menu to Sidebar Panel

Here is the easiest way I have found to add flyout or drop down menus to a particular panel in an Interspire shopping cart’s template.

First, sign  into the website’s admin panel.

Go to Settings -> Store Settings -> Display.

In the box next to Category List Depth, change the number to the number of levels you want to display in the flyout or drop down menu.

Now, go to Store Design and then click Browse Template files.

In your website template’s style.css file, add this code:

.Left #SideCategoryList li:hover, .CategoryList li:hover, .CategoryList li.Over {
background: #746755;
}
.Left #SideCategoryList li:hover a, .CategoryList li:hover a {
color: #fff;
}
.Left #SideCategoryList li ul, .CategoryList li ul {
display: none;
padding: 0 0 9px 0;
-moz-border-radius-bottomleft: 17px;
-moz-border-radius-topright: 17px;
-webkit-border-top-right-radius: 17px;
-webkit-border-bottom-left-radius: 17px;
width: 160px;
position: absolute;
}
.Left #SideCategoryList li:hover ul, .CategoryList li:hover ul {
display: block;
position:absolute;
margin-top:-15px;
left:160px;
width:160px;
}
.Left #SideCategoryList li:hover li, .CategoryList li:hover li {
float: none;
background: #f0eee8;
}
.Left #SideCategoryList li:hover li a, .CategoryList li:hover li a {
color: #444;
font-size: 14px;
text-transform: none;
font-style: normal;
border-top: 1px solid #f0eee8;
border-bottom: 1px solid #f0eee8;
}
.Left #SideCategoryList li li a:hover, .CategoryList li li a:hover {
background: #746755;
color: #fff;
border-color: #fefaf3;
}
.Left #SideCategoryList li:hover, .CategoryList li:hover {
background: #746755;
}
.Left #SideCategoryList li:hover a, .CategoryList li:hover a {color: #fff;}

.Left #SideCategoryList li ul, .CategoryList li ul {display: none;padding: 0 0 9px 0;-moz-border-radius-bottomleft: 17px;-moz-border-radius-topright: 17px;-webkit-border-top-right-radius: 17px;-webkit-border-bottom-left-radius: 17px;width: 160px;position: absolute;
}
.Left #SideCategoryList li:hover ul, .CategoryList li:hover ul {display: block;position:absolute;margin-top:-15px;left:160px;width:160px;
}
.Left #SideCategoryList li:hover li, .CategoryList li:hover li {float: none;background: #f0eee8;}
.Left #SideCategoryList li:hover li a, .CategoryList li:hover li a {color: #444;font-size: 14px;text-transform: none;font-style: normal;border-top: 1px solid #f0eee8;border-bottom: 1px solid #f0eee8;}
.Left #SideCategoryList li li a:hover, .CategoryList li li a:hover {background: #746755;color: #fff;border-color: #fefaf3;}

This code will add a flyout menu to the Category panel in the left sidebar of your website. You can change the name of the panel in the codes if you want to apply the flyout menu to another panel.

Next, you will want to edit the styles above to match the design of your own site.

And that’s all you need to create flyout or dropdown menus for the sidebar of your Interspire shopping cart template!

Let me know if you run into any issues or have any questions.

You can also learn how to create your own custom panels for Interspire shopping carts in another post I wrote.

WP E-Commerce plug in: fixing output from USPS rate calculator

I have used the WP E-commerce plug in for several WordPress online stores that I have developed for clients, and one thing that I have run into more than once is this: the names of the carriers when you calculate USPS shipping rates often have an unsightly line of code in them:

Priority Mail® Flat Rate Envelope
Express Mail® Flat Rate Envelope
Parcel Post®

Here is the way to fix it. Open  wp-e-commerce/wpsc-includes/cart.class.php and find this line of code:

function wpsc_shipping_quote_name() {
 global $wpsc_cart;
 return $wpsc_cart->shipping_quote['name'];
}

Replace that block of code with this:

function wpsc_shipping_quote_name() {
	global $wpsc_cart;
	//return $wpsc_cart->shipping_quote['name'];

   $output .= $wpsc_cart->shipping_quote['name'];
+  $output = str_replace('&lt;sup>&amp;reg;&lt;/sup>', '<sup>&reg;</sup>', $output);
+  $output = str_replace('&lt;sup>&amp;trade;&lt;/sup>', '<sup>&trade;</sup>', $output);

   return $output;
 }

Now simply save the file and your problem should be fixed! That has worked every time for me, but let me know if you have any trouble.