WordPress Simple PayPal Shopping Cart - Version 2.6

Version Description

Download this release

Release Info

Developer mra13
Plugin Icon 128x128 WordPress Simple PayPal Shopping Cart
Version 2.6
Comparing to
See all releases

Code changes from version 1.7 to 2.6

images/Shoppingcart_delete.png ADDED
Binary file
images/add_to_cart_button_76.png ADDED
Binary file
images/shopping_cart_icon.png ADDED
Binary file
readme.txt CHANGED
@@ -1,23 +1,51 @@
1
  === WordPress Simple Paypal Shopping Cart ===
2
  Contributors: Ruhul Amin
3
- Donate link: http://www.tipsandtricks-hq.com/development-center
4
- Tags: Paypal shopping cart, online shop, shopping cart, online checkout system, sell digital products
5
- Requires at least: 2.5
6
- Tested up to: 2.7.1
7
- Stable tag: 1.8
8
 
9
- Very easy to use Simple Paypal Shopping Cart Plugin. Great for selling digital products online in one click.
10
 
11
  == Description ==
12
 
13
- WordPress Simple Paypal Shopping Cart adds a 'Add to Cart' button on any post or page. It allows you to add the shopping cart to any post or page or sidebar easily. The shows the user what they currently have in the cart and allows them to remove the items.
14
 
15
- For screenshots, more information and updates, please visit:
16
  http://www.tipsandtricks-hq.com/?p=768
 
 
17
 
18
- Usage:
19
  1. To add the 'Add to Cart' button simply add the trigger text [wp_cart:PRODUCT-NAME:price:PRODUCT-PRICE:end] to a post or page next to the product. Replace PRODUCT-NAME and PRODUCT-PRICE with the actual name and price.
20
- 2. To add the shopping cart to a post or page simply add the trigger text <!--show-wp-shopping-cart--> to a post or page. Use the sidebar widget to display the shopping cart on the sidebar. The shopping cart will only be visible in a post or page when a customer adds a product.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
  == Installation ==
23
 
@@ -38,5 +66,8 @@ Usage:
38
  == Screenshots ==
39
  Visit the plugin site at http://www.tipsandtricks-hq.com/?p=768 for screenshots.
40
 
 
 
 
41
 
42
 
1
  === WordPress Simple Paypal Shopping Cart ===
2
  Contributors: Ruhul Amin
3
+ Donate link: http://www.tipsandtricks-hq.com
4
+ Tags: WordPress shopping cart, Paypal shopping cart, online shop, shopping cart, wordperss ecommerce, sell digital products
5
+ Requires at least: 2.6
6
+ Tested up to: 2.8.6
7
+ Stable tag:2.6
8
 
9
+ Very easy to use Simple WordPress Paypal Shopping Cart Plugin. Great for selling products online in one click from your WordPress site.
10
 
11
  == Description ==
12
 
13
+ WordPress Simple Paypal Shopping Cart allows you to add an 'Add to Cart' button on any posts or pages. It also allows you to add/display the shopping cart on any post or page or sidebar easily. The shopping cart shows the user what they currently have in the cart and allows them to remove the items. It can be easily integrated with the NextGen Photo Gallery plugin too.
14
 
15
+ For screenshots, detailed documentation, support and updates, please visit:
16
  http://www.tipsandtricks-hq.com/?p=768
17
+ or
18
+ http://www.tipsandtricks-hq.com/ecommerce/wp-shopping-cart
19
 
20
+ == Usage ==
21
  1. To add the 'Add to Cart' button simply add the trigger text [wp_cart:PRODUCT-NAME:price:PRODUCT-PRICE:end] to a post or page next to the product. Replace PRODUCT-NAME and PRODUCT-PRICE with the actual name and price.
22
+ 2. To add the 'Add to Cart' button on the sidebar or from other template files use the following function:
23
+ <?php echo print_wp_cart_button_for_product('PRODUCT-NAME', PRODUCT-PRICE); ?>
24
+ Replace PRODUCT-NAME and PRODUCT-PRICE with the actual name and price.
25
+ 3. To add the shopping cart to a post or page (eg. checkout page) simply add the shortcode [show_wp_shopping_cart] to a post or page or use the sidebar widget to add the shopping cart to the sidebar. The shopping cart will only be visible in a post or page when a customer adds a product.
26
+
27
+ Using Shipping
28
+ 1. To use shipping cost use the following trigger text
29
+ [wp_cart:PRODUCT-NAME:price:PRODUCT-PRICE:shipping:SHIPPING-COST:end]
30
+
31
+ or use the following php function from your wordpress template files
32
+ <?php echo print_wp_cart_button_for_product('product name',price,shipping cost); ?>
33
+
34
+ Using Variation Control
35
+ 1. To use variation control use the following trigger text
36
+ [wp_cart:PRODUCT-NAME:price:PRODUCT-PRICE:var1[VARIATION-NAME|VARIATION1|VARIATION2|VARIATION3]:end]
37
+
38
+ eg. [wp_cart:Demo Product 1:price:15:var1[Size|Small|Medium|Large]:end]
39
+
40
+ 2. To use variation control with shipping use the following trigger text:
41
+ [wp_cart:PRODUCT-NAME:price:PRODUCT-PRICE:shipping:SHIPPING-COST:var1[VARIATION-NAME|VARIATION1|VARIATION2|VARIATION3]:end]
42
+
43
+ eg. [wp_cart:Demo Product 1:price:15:shipping:2:var1[Size|Small|Medium|Large]:end]
44
+
45
+ 3. To use multiple variation option use the following trigger text:
46
+ [wp_cart:PRODUCT-NAME:price:PRODUCT-PRICE:var1[VARIATION-NAME|VARIATION1|VARIATION2|VARIATION3]:var2[VARIATION-NAME|VARIATION1|VARIATION2]:end]
47
+
48
+ eg. [wp_cart:Demo Product 1:price:15:shipping:2:var1[Size|Small|Medium|Large]:var2[Color|Red|Green]:end]
49
 
50
  == Installation ==
51
 
66
  == Screenshots ==
67
  Visit the plugin site at http://www.tipsandtricks-hq.com/?p=768 for screenshots.
68
 
69
+ == Changelog ==
70
+ Changelog can be found at the following URL
71
+ http://www.tipsandtricks-hq.com/ecommerce/?p=319
72
 
73
 
wp_shopping_cart.php CHANGED
@@ -1,11 +1,11 @@
1
  <?php
2
  /*
3
  Plugin Name: WP Simple Paypal Shopping cart
4
- Version: v1.6
5
  Plugin URI: http://www.tipsandtricks-hq.com/?p=768
6
  Author: Ruhul Amin
7
  Author URI: http://www.tipsandtricks-hq.com/
8
- Description: Simple Paypal Shopping Cart Plugin, very easy to use and great for selling digital products or service from your blog!
9
  */
10
 
11
  /*
@@ -31,6 +31,15 @@ add_option('wp_cart_title', 'Your Shopping Cart');
31
  add_option('wp_cart_empty_text', 'Your cart is empty');
32
  add_option('cart_return_from_paypal_url', get_bloginfo('wpurl'));
33
 
 
 
 
 
 
 
 
 
 
34
  function shopping_cart_show($content)
35
  {
36
  if (strpos($content, "<!--show-wp-shopping-cart-->") !== FALSE)
@@ -66,6 +75,7 @@ function reset_wp_cart()
66
  unset($products[$key]);
67
  }
68
  $_SESSION['simpleCart'] = $products;
 
69
  }
70
 
71
  if ($_POST['addcart'])
@@ -98,7 +108,7 @@ if ($_POST['addcart'])
98
  else
99
  $price = $_POST['price'];
100
 
101
- $product = array('name' => stripslashes($_POST['product']), 'price' => $price, 'quantity' => $count, 'cartLink' => $_POST['cartLink'], 'item_number' => $_POST['item_number']);
102
  array_push($products, $product);
103
  }
104
 
@@ -142,10 +152,15 @@ function print_wp_shopping_cart()
142
  {
143
  $output .= $empty_cart_text;
144
  }
 
 
 
 
 
145
  return $output;
146
  }
147
  $email = get_bloginfo('admin_email');
148
-
149
  $defaultCurrency = get_option('cart_payment_currency');
150
  $defaultSymbol = get_option('cart_currency_symbol');
151
  $defaultEmail = get_option('cart_paypal_email');
@@ -168,7 +183,15 @@ function print_wp_shopping_cart()
168
 
169
  if (!empty($return))
170
  $urls .= '<input type="hidden" name="return" value="'.$return.'" />';
171
-
 
 
 
 
 
 
 
 
172
  $title = get_option('wp_cart_title');
173
  //if (empty($title)) $title = 'Your Shopping Cart';
174
 
@@ -176,7 +199,7 @@ function print_wp_shopping_cart()
176
  $output .= '<div class="shopping_cart" style=" padding: 5px;">';
177
  if (!get_option('wp_shopping_cart_image_hide'))
178
  {
179
- $output .= "<input type='image' src='".WP_CART_URL."/images/shopping_cart_icon.gif' value='Cart' title='Cart' />";
180
  }
181
  if(!empty($title))
182
  {
@@ -196,65 +219,85 @@ function print_wp_shopping_cart()
196
  {
197
  $output .= '
198
  <tr>
199
- <th>Item Name</th><th>Quantity</th><th>Price</th>
200
  </tr>';
201
 
202
- foreach ($_SESSION['simpleCart'] as $item)
203
- {
204
- $total += $item['price'] * $item['quantity'];
205
-
206
- $total_items += $item['quantity'];
207
- }
208
-
209
- foreach ($_SESSION['simpleCart'] as $item)
210
- {
211
- $output .= "
212
- <tr><td style='overflow: hidden;'><a href='".$item['cartLink']."'>".$item['name']."</a></td>
213
- <td style='text-align: center'><form method=\"post\" action=\"\" name='pcquantity' style='display: inline'>
214
- <input type='hidden' name='product' value='".$item['name']."' />
215
-
216
- <input type='hidden' name='cquantity' value='1' /><input type='text' name='quantity' value='".$item['quantity']."' size='1' onchange='document.pcquantity.submit();' onkeypress='document.getElementById(\"pinfo\").style.display = \"\";' /></form></td>
217
- <td style='text-align: center'>".print_payment_currency(($item['price'] * $item['quantity']), $paypal_symbol, $decimal)."</td>
218
- <td><form method=\"post\" action=\"\">
219
- <input type='hidden' name='product' value='".$item['name']."' />
220
- <input type='hidden' name='delcart' value='1' />
221
- <input type='image' src='".WP_CART_URL."/images/Shoppingcart_delete.gif' value='Remove' title='Remove' /></form></td></tr>
222
-
223
- ";
224
-
225
- $form .= "
226
- <input type=\"hidden\" name=\"item_name_$count\" value=\"".$item['name']."\" />
227
- <input type=\"hidden\" name=\"amount_$count\" value='".$item['price']."' />
228
- <input type=\"hidden\" name=\"quantity_$count\" value=\"".$item['quantity']."\" />
229
- <input type='hidden' name='item_number' value='".$item['item_number']."' />
230
- ";
231
- $form .= "<input type=\"hidden\" name=\"shipping_$count\" value=\"0\" />";
232
- $count++;
233
- }
 
 
 
 
 
 
 
 
234
  }
235
 
236
  $count--;
237
 
238
  if ($count)
239
  {
240
- $output .= '<tr><td></td><td></td><td></td></tr>';
241
- $output .= "
242
- <tr><td colspan='2' style='font-weight: bold; text-align: right;'>Total: </td><td style='text-align: center'>".print_payment_currency(($total), $paypal_symbol, $decimal)."</td><td></td></tr>
 
 
 
 
 
 
 
 
243
  <tr><td colspan='4'>";
244
 
245
  $output .= "<form action=\"https://www.paypal.com/us/cgi-bin/webscr\" method=\"post\">$form";
246
  if ($count)
247
- $output .= '<input type="image" src="'.WP_CART_URL.'/images/paypal_checkout.png" name="submit" alt="Make payments with PayPal - it\'s fast, free and secure!" />';
248
 
249
  $output .= $urls.'
250
  <input type="hidden" name="business" value="'.$email.'" />
251
  <input type="hidden" name="currency_code" value="'.$paypal_currency.'" />
252
  <input type="hidden" name="cmd" value="_cart" />
253
  <input type="hidden" name="upload" value="1" />
254
- </form>';
 
 
 
 
 
255
  }
256
- $output .= "
257
-
258
  </td></tr>
259
  </table></div>
260
  ";
@@ -264,56 +307,186 @@ function print_wp_shopping_cart()
264
  // https://www.sandbox.paypal.com/cgi-bin/webscr (paypal testing site)
265
  // https://www.paypal.com/us/cgi-bin/webscr (paypal live site )
266
 
267
- function print_wp_cart_button($content)
268
- {
269
- $addcart = get_option('addToCartButtonName');
270
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
271
  if (!$addcart || ($addcart == '') )
272
  $addcart = 'Add to Cart';
273
-
274
- $pattern = '#\[wp_cart:.+:price:#';
275
  preg_match_all ($pattern, $content, $matches);
276
-
277
  foreach ($matches[0] as $match)
278
- {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
279
  $pattern = '[wp_cart:';
280
  $m = str_replace ($pattern, '', $match);
281
- $pattern = ':price:';
282
- $m = str_replace ($pattern, '', $m);
283
-
284
- $pieces = explode('|',$m);
285
 
286
- if (sizeof($pieces) == 1)
287
- {
288
- $replacement = '<object><form method="post" action="" style="display:inline">';
289
- if (preg_match("/http:/", $addcart)) // Use the image as the 'add to cart' button
 
 
 
 
 
 
 
 
 
 
 
 
290
  {
291
- $replacement .= '<input type="image" src="'.$addcart.'" alt="Add to Cart"/>';
292
  }
293
  else
294
  {
295
  $replacement .= '<input type="submit" value="'.$addcart.'" />';
296
- }
297
-
298
- $replacement .= '<input type="hidden" name="product" value="'.$pieces['0'].
299
- '" /><input type="hidden" name="price" value="';
300
-
301
- $content = str_replace ($match, $replacement, $content);
302
- }
303
- $forms = str_replace(':item_num:',
304
- '" /><input type="hidden" name="shipping" value="',
305
- $content);
306
-
307
- $forms = str_replace(':end]',
308
- '" /><input type="hidden" name="addcart" value="1" /><input type="hidden" name="cartLink" value="'.cart_current_page_url().'" />
309
- </form></object>',
310
- $forms);
311
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
312
 
313
- if (empty($forms))
314
- $forms = $content;
315
-
316
- return $forms;
 
 
 
 
 
 
 
 
 
 
 
 
 
317
  }
318
 
319
  function cart_not_empty()
@@ -346,9 +519,26 @@ function cart_current_page_url() {
346
  return $pageURL;
347
  }
348
 
349
- function show_wp_cart_options_page () {
350
-
351
- $wp_simple_paypal_shopping_cart_version = 1.6;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
352
 
353
  $defaultCurrency = get_option('cart_payment_currency');
354
  if (empty($defaultCurrency)) $defaultCurrency = 'USD';
@@ -356,6 +546,11 @@ function show_wp_cart_options_page () {
356
  $defaultSymbol = get_option('cart_currency_symbol');
357
  if (empty($defaultSymbol)) $defaultSymbol = '$';
358
 
 
 
 
 
 
359
  $defaultEmail = get_option('cart_paypal_email');
360
  if (empty($defaultEmail)) $defaultEmail = get_bloginfo('admin_email');
361
 
@@ -368,43 +563,52 @@ function show_wp_cart_options_page () {
368
  //if (empty($title)) $title = 'Your Shopping Cart';
369
 
370
  $emptyCartText = get_option('wp_cart_empty_text');
371
-
 
372
  if (get_option('wp_shopping_cart_image_hide'))
373
  $wp_cart_image_hide = 'checked="checked"';
374
  else
375
  $wp_cart_image_hide = '';
376
-
 
 
 
 
 
377
  ?>
378
  <h2>Simple Paypal Shopping Cart Settings v <?php echo $wp_simple_paypal_shopping_cart_version; ?></h2>
379
 
380
- <p>For information and updates, please visit:<br />
381
  <a href="http://www.tipsandtricks-hq.com/?p=768">http://www.tipsandtricks-hq.com/?p=768</a></p>
382
 
383
  <fieldset class="options">
384
  <legend>Usage:</legend>
385
 
386
- <p>1. To add the 'Add to Cart' button simply add the trigger text <strong>[wp_cart:PRODUCT-NAME:price:PRODUCT-PRICE:end]</strong> to a post or page next to the product. Replace PRODUCT-NAME and PRODUCT-PRICE with the actual name and price.</p>
387
- <p>2. To add the shopping cart to a post or checkout page or sidebar simply add the trigger text <strong>&lt;!--show-wp-shopping-cart--&gt;</strong> to a post or page or use the sidebar widget. The shopping cart will only be visible when a customer adds a product.
388
  </fieldset>
389
-
 
 
390
  <?php
391
-
392
- echo '
393
- <form method="post" action="options.php">';
394
- wp_nonce_field('update-options');
395
- echo '
 
396
  <table class="form-table">
397
  <tr valign="top">
398
  <th scope="row">Paypal Email Address</th>
399
- <td><input type="text" name="cart_paypal_email" value="'.$defaultEmail.'" /></td>
400
  </tr>
401
  <tr valign="top">
402
  <th scope="row">Shopping Cart title</th>
403
- <td><input type="text" name="wp_cart_title" value="'.$title.'" /></td>
404
  </tr>
405
  <tr valign="top">
406
  <th scope="row">Text to show when Cart empty</th>
407
- <td><input type="text" name="wp_cart_empty_text" value="'.$emptyCartText.'" /></td>
408
  </tr>
409
  <tr valign="top">
410
  <th scope="row">Currency</th>
@@ -416,38 +620,61 @@ function show_wp_cart_options_page () {
416
  </td>
417
  </tr>
418
 
 
 
 
 
 
 
 
 
 
 
419
  <tr valign="top">
420
  <th scope="row">Add to Cart button text or Image</th>
421
- <td><input type="text" name="addToCartButtonName" value="'.$addcart.'" size="70" /><br />To use a cusomized image as the button simply enter the URL of the image file. eg. http://www.tipsandtricks-hq.com/wp-content/plugins/wordpress-paypal-shopping-cart/images/buy_now_button.png</td>
422
  </tr>
423
 
424
  <tr valign="top">
425
  <th scope="row">Return URL</th>
426
- <td><input type="text" name="cart_return_from_paypal_url" value="'.$return_url.'" size="70" /><br />This is the URL the customer will be redirected to after a successful payment</td>
 
 
 
 
 
427
  </tr>
428
  </table>
429
 
 
430
  <table class="form-table">
431
  <tr valign="top">
432
  <th scope="row">Hide Shopping Cart Image</th>
433
  <td><input type="checkbox" name="wp_shopping_cart_image_hide" value="1" '.$wp_cart_image_hide.' /><br />If ticked the shopping cart image will no be shown.</td>
434
  </tr>
435
  </table>
436
-
437
- <p class="submit">
438
- <input type="submit" name="Submit" value="Update Options &raquo;" />
439
- <input type="hidden" name="action" value="update" />
440
- <input type="hidden" name="page_options" value="cart_payment_currency,cart_currency_symbol,cart_paypal_email,addToCartButtonName,wp_cart_title,wp_cart_empty_text,cart_return_from_paypal_url,wp_shopping_cart_image_hide" />
441
- </p>
442
 
 
 
 
 
 
 
 
 
 
 
443
  </form>
444
  ';
 
445
  }
446
 
447
  function wp_cart_options()
448
  {
449
  echo '<div class="wrap"><h2>WP Paypal Shopping Cart Options</h2>';
 
450
  show_wp_cart_options_page();
 
451
  echo '</div>';
452
  }
453
 
@@ -486,13 +713,21 @@ function widget_wp_paypal_shopping_cart_init()
486
  wp_register_widget_control('wp_paypal_shopping_cart_widgets', __('WP Paypal Shopping Cart'), 'wp_paypal_shopping_cart_widget_control' );
487
  }
488
 
 
 
 
 
 
489
  // Insert the options page to the admin menu
490
  add_action('admin_menu','wp_cart_options_page');
491
-
492
  add_action('init', 'widget_wp_paypal_shopping_cart_init');
 
493
 
494
- add_filter('the_content', 'print_wp_cart_button',11);
495
-
496
  add_filter('the_content', 'shopping_cart_show');
497
 
 
 
 
 
498
  ?>
1
  <?php
2
  /*
3
  Plugin Name: WP Simple Paypal Shopping cart
4
+ Version: v2.6
5
  Plugin URI: http://www.tipsandtricks-hq.com/?p=768
6
  Author: Ruhul Amin
7
  Author URI: http://www.tipsandtricks-hq.com/
8
+ Description: Simple WordPress Shopping Cart Plugin, very easy to use and great for selling products and services from your blog!
9
  */
10
 
11
  /*
31
  add_option('wp_cart_empty_text', 'Your cart is empty');
32
  add_option('cart_return_from_paypal_url', get_bloginfo('wpurl'));
33
 
34
+ function show_wp_shopping_cart_handler()
35
+ {
36
+ if (cart_not_empty())
37
+ {
38
+ $output = print_wp_shopping_cart();
39
+ }
40
+ return $output;
41
+ }
42
+
43
  function shopping_cart_show($content)
44
  {
45
  if (strpos($content, "<!--show-wp-shopping-cart-->") !== FALSE)
75
  unset($products[$key]);
76
  }
77
  $_SESSION['simpleCart'] = $products;
78
+ header('Location: ' . get_option('cart_return_from_paypal_url'));
79
  }
80
 
81
  if ($_POST['addcart'])
108
  else
109
  $price = $_POST['price'];
110
 
111
+ $product = array('name' => stripslashes($_POST['product']), 'price' => $price, 'quantity' => $count, 'shipping' => $_POST['shipping'], 'cartLink' => $_POST['cartLink'], 'item_number' => $_POST['item_number']);
112
  array_push($products, $product);
113
  }
114
 
152
  {
153
  $output .= $empty_cart_text;
154
  }
155
+ $cart_products_page_url = get_option('cart_products_page_url');
156
+ if (!empty($cart_products_page_url))
157
+ {
158
+ $output .= '<br /><a rel="nofollow" href="'.$cart_products_page_url.'">Visit The Shop</a>';
159
+ }
160
  return $output;
161
  }
162
  $email = get_bloginfo('admin_email');
163
+ $use_affiliate_platform = get_option('wp_use_aff_platform');
164
  $defaultCurrency = get_option('cart_payment_currency');
165
  $defaultSymbol = get_option('cart_currency_symbol');
166
  $defaultEmail = get_option('cart_paypal_email');
183
 
184
  if (!empty($return))
185
  $urls .= '<input type="hidden" name="return" value="'.$return.'" />';
186
+
187
+ if ($use_affiliate_platform)
188
+ {
189
+ if (function_exists('wp_aff_platform_install'))
190
+ {
191
+ $notify = WP_CART_URL.'/paypal.php';
192
+ $urls .= '<input type="hidden" name="notify_url" value="'.$notify.'" />';
193
+ }
194
+ }
195
  $title = get_option('wp_cart_title');
196
  //if (empty($title)) $title = 'Your Shopping Cart';
197
 
199
  $output .= '<div class="shopping_cart" style=" padding: 5px;">';
200
  if (!get_option('wp_shopping_cart_image_hide'))
201
  {
202
+ $output .= "<input type='image' src='".WP_CART_URL."/images/shopping_cart_icon.png' value='Cart' title='Cart' />";
203
  }
204
  if(!empty($title))
205
  {
219
  {
220
  $output .= '
221
  <tr>
222
+ <th style="text-align: left">Item Name</th><th>Quantity</th><th>Price</th>
223
  </tr>';
224
 
225
+ foreach ($_SESSION['simpleCart'] as $item)
226
+ {
227
+ $total += $item['price'] * $item['quantity'];
228
+ $item_total_shipping += $item['shipping'] * $item['quantity'];
229
+ $total_items += $item['quantity'];
230
+ }
231
+ $baseShipping = get_option('cart_base_shipping_cost');
232
+ $postage_cost = $item_total_shipping + $baseShipping;
233
+
234
+ $cart_free_shipping_threshold = get_option('cart_free_shipping_threshold');
235
+ if (!empty($cart_free_shipping_threshold) && $total > $cart_free_shipping_threshold)
236
+ {
237
+ $postage_cost = 0;
238
+ }
239
+
240
+ foreach ($_SESSION['simpleCart'] as $item)
241
+ {
242
+ $output .= "
243
+ <tr><td style='overflow: hidden;'><a href='".$item['cartLink']."'>".$item['name']."</a></td>
244
+ <td style='text-align: center'><form method=\"post\" action=\"\" name='pcquantity' style='display: inline'>
245
+ <input type='hidden' name='product' value='".$item['name']."' />
246
+
247
+ <input type='hidden' name='cquantity' value='1' /><input type='text' name='quantity' value='".$item['quantity']."' size='1' onchange='document.pcquantity.submit();' onkeypress='document.getElementById(\"pinfo\").style.display = \"\";' /></form></td>
248
+ <td style='text-align: center'>".print_payment_currency(($item['price'] * $item['quantity']), $paypal_symbol, $decimal)."</td>
249
+ <td><form method=\"post\" action=\"\">
250
+ <input type=\"hidden\" name=\"product\" value=\"".$item['name']."\" />
251
+ <input type='hidden' name='delcart' value='1' />
252
+ <input type='image' src='".WP_CART_URL."/images/Shoppingcart_delete.png' value='Remove' title='Remove' /></form></td></tr>
253
+
254
+ ";
255
+
256
+ $form .= "
257
+ <input type=\"hidden\" name=\"item_name_$count\" value=\"".$item['name']."\" />
258
+ <input type=\"hidden\" name=\"amount_$count\" value='".$item['price']."' />
259
+ <input type=\"hidden\" name=\"quantity_$count\" value=\"".$item['quantity']."\" />
260
+ <input type='hidden' name='item_number' value='".$item['item_number']."' />
261
+ ";
262
+ $count++;
263
+ }
264
+ $form .= "<input type=\"hidden\" name=\"shipping_1\" value='".$postage_cost."' />";
265
  }
266
 
267
  $count--;
268
 
269
  if ($count)
270
  {
271
+ //$output .= '<tr><td></td><td></td><td></td></tr>';
272
+
273
+ if ($postage_cost != 0)
274
+ {
275
+ $output .= "
276
+ <tr><td colspan='2' style='font-weight: bold; text-align: right;'>Subtotal: </td><td style='text-align: center'>".print_payment_currency($total, $paypal_symbol, $decimal)."</td><td></td></tr>
277
+ <tr><td colspan='2' style='font-weight: bold; text-align: right;'>Shipping: </td><td style='text-align: center'>".print_payment_currency($postage_cost, $paypal_symbol, $decimal)."</td><td></td></tr>";
278
+ }
279
+
280
+ $output .= "
281
+ <tr><td colspan='2' style='font-weight: bold; text-align: right;'>Total: </td><td style='text-align: center'>".print_payment_currency(($total+$postage_cost), $paypal_symbol, $decimal)."</td><td></td></tr>
282
  <tr><td colspan='4'>";
283
 
284
  $output .= "<form action=\"https://www.paypal.com/us/cgi-bin/webscr\" method=\"post\">$form";
285
  if ($count)
286
+ $output .= '<input type="image" src="'.WP_CART_URL.'/images/paypal_checkout.png" name="submit" class="wp_cart_checkout_button" alt="Make payments with PayPal - it\'s fast, free and secure!" />';
287
 
288
  $output .= $urls.'
289
  <input type="hidden" name="business" value="'.$email.'" />
290
  <input type="hidden" name="currency_code" value="'.$paypal_currency.'" />
291
  <input type="hidden" name="cmd" value="_cart" />
292
  <input type="hidden" name="upload" value="1" />
293
+ <input type="hidden" name="mrb" value="3FWGC6LFTMTUG" />';
294
+ if ($use_affiliate_platform)
295
+ {
296
+ $output .= wp_cart_add_custom_field();
297
+ }
298
+ $output .= '</form>';
299
  }
300
+ $output .= "
 
301
  </td></tr>
302
  </table></div>
303
  ";
307
  // https://www.sandbox.paypal.com/cgi-bin/webscr (paypal testing site)
308
  // https://www.paypal.com/us/cgi-bin/webscr (paypal live site )
309
 
310
+ function wp_cart_add_custom_field()
311
+ {
312
+ if (function_exists('wp_aff_platform_install'))
313
+ {
314
+ $output = '';
315
+ if (!empty($_SESSION['ap_id']))
316
+ {
317
+ $output = '<input type="hidden" name="custom" value="'.$_SESSION['ap_id'].'" id="wp_affiliate" />';
318
+ }
319
+ else if (isset($_COOKIE['ap_id']))
320
+ {
321
+ $output = '<input type="hidden" name="custom" value="'.$_COOKIE['ap_id'].'" id="wp_affiliate" />';
322
+ }
323
+ return $output;
324
+ }
325
+ }
326
+
327
+ function print_wp_cart_button_new($content)
328
+ {
329
+ //wp_cart_add_read_form_javascript();
330
+
331
+ $addcart = get_option('addToCartButtonName');
332
  if (!$addcart || ($addcart == '') )
333
  $addcart = 'Add to Cart';
334
+
335
+ $pattern = '#\[wp_cart:.+:price:.+:end]#';
336
  preg_match_all ($pattern, $content, $matches);
337
+
338
  foreach ($matches[0] as $match)
339
+ {
340
+ $var_output = '';
341
+ $pos = strpos($match,":var1");
342
+ if ($pos)
343
+ {
344
+ $match_tmp = $match;
345
+ // Variation control is used
346
+ $pos2 = strpos($match,":var2");
347
+ if ($pos2)
348
+ {
349
+ //echo '<br />'.$match_tmp.'<br />';
350
+ $pattern = '#var2\[.*]:#';
351
+ preg_match_all ($pattern, $match_tmp, $matches3);
352
+ $match3 = $matches3[0][0];
353
+ //echo '<br />'.$match3.'<br />';
354
+ $match_tmp = str_replace ($match3, '', $match_tmp);
355
+
356
+ $pattern = 'var2[';
357
+ $m3 = str_replace ($pattern, '', $match3);
358
+ $pattern = ']:';
359
+ $m3 = str_replace ($pattern, '', $m3);
360
+ $pieces3 = explode('|',$m3);
361
+
362
+ $variation2_name = $pieces3[0];
363
+ $var_output .= $variation2_name." : ";
364
+ $var_output .= '<select name="variation2" onchange="ReadForm (this.form, false);">';
365
+ for ($i=1;$i<sizeof($pieces3); $i++)
366
+ {
367
+ $var_output .= '<option value="'.$pieces3[$i].'">'.$pieces3[$i].'</option>';
368
+ }
369
+ $var_output .= '</select><br />';
370
+ }
371
+
372
+ $pattern = '#var1\[.*]:#';
373
+ preg_match_all ($pattern, $match_tmp, $matches2);
374
+ $match2 = $matches2[0][0];
375
+
376
+ $match_tmp = str_replace ($match2, '', $match_tmp);
377
+
378
+ $pattern = 'var1[';
379
+ $m2 = str_replace ($pattern, '', $match2);
380
+ $pattern = ']:';
381
+ $m2 = str_replace ($pattern, '', $m2);
382
+ $pieces2 = explode('|',$m2);
383
+
384
+ $variation_name = $pieces2[0];
385
+ $var_output .= $variation_name." : ";
386
+ $var_output .= '<select name="variation1" onchange="ReadForm (this.form, false);">';
387
+ for ($i=1;$i<sizeof($pieces2); $i++)
388
+ {
389
+ $var_output .= '<option value="'.$pieces2[$i].'">'.$pieces2[$i].'</option>';
390
+ }
391
+ $var_output .= '</select><br />';
392
+
393
+ }
394
+
395
  $pattern = '[wp_cart:';
396
  $m = str_replace ($pattern, '', $match);
 
 
 
 
397
 
398
+ $pattern = 'price:';
399
+ $m = str_replace ($pattern, '', $m);
400
+ $pattern = 'shipping:';
401
+ $m = str_replace ($pattern, '', $m);
402
+ $pattern = ':end]';
403
+ $m = str_replace ($pattern, '', $m);
404
+
405
+ $pieces = explode(':',$m);
406
+
407
+ $replacement = '<object><form method="post" action="" style="display:inline" onsubmit="return ReadForm(this, true);">';
408
+ if (!empty($var_output))
409
+ {
410
+ $replacement .= $var_output;
411
+ }
412
+
413
+ if (preg_match("/http/", $addcart)) // Use the image as the 'add to cart' button
414
  {
415
+ $replacement .= '<input type="image" src="'.$addcart.'" class="wp_cart_button" alt="Add to Cart"/>';
416
  }
417
  else
418
  {
419
  $replacement .= '<input type="submit" value="'.$addcart.'" />';
420
+ }
421
+
422
+ $replacement .= '<input type="hidden" name="product" value="'.$pieces['0'].'" /><input type="hidden" name="price" value="'.$pieces['1'].'" />';
423
+ $replacement .= '<input type="hidden" name="product_tmp" value="'.$pieces['0'].'" />';
424
+ if (sizeof($pieces) >2 )
425
+ {
426
+ //we have shipping
427
+ $replacement .= '<input type="hidden" name="shipping" value="'.$pieces['2'].'" />';
428
+ }
429
+ $replacement .= '<input type="hidden" name="cartLink" value="'.cart_current_page_url().'" />';
430
+ $replacement .= '<input type="hidden" name="addcart" value="1" /></form></object>';
431
+ $content = str_replace ($match, $replacement, $content);
432
+ }
433
+ return $content;
434
+ }
435
+
436
+ function wp_cart_add_read_form_javascript()
437
+ {
438
+ echo '
439
+ <script type="text/javascript">
440
+ <!--
441
+ //
442
+ function ReadForm (obj1, tst)
443
+ {
444
+ // Read the user form
445
+ var i,j,pos;
446
+ val_total="";val_combo="";
447
+
448
+ for (i=0; i<obj1.length; i++)
449
+ {
450
+ // run entire form
451
+ obj = obj1.elements[i]; // a form element
452
+
453
+ if (obj.type == "select-one")
454
+ { // just selects
455
+ if (obj.name == "quantity" ||
456
+ obj.name == "amount") continue;
457
+ pos = obj.selectedIndex; // which option selected
458
+ val = obj.options[pos].value; // selected value
459
+ val_combo = val_combo + "(" + val + ")";
460
+ }
461
+ }
462
+ // Now summarize everything we have processed above
463
+ val_total = obj1.product_tmp.value + val_combo;
464
+ obj1.product.value = val_total;
465
+ }
466
+ //-->
467
+ </script>';
468
+ }
469
+ function print_wp_cart_button_for_product($name, $price, $shipping=0)
470
+ {
471
+ $addcart = get_option('addToCartButtonName');
472
 
473
+ if (!$addcart || ($addcart == '') )
474
+ $addcart = 'Add to Cart';
475
+
476
+
477
+ $replacement = '<object><form method="post" action="" style="display:inline">';
478
+ if (preg_match("/http:/", $addcart)) // Use the image as the 'add to cart' button
479
+ {
480
+ $replacement .= '<input type="image" src="'.$addcart.'" class="wp_cart_button" alt="Add to Cart"/>';
481
+ }
482
+ else
483
+ {
484
+ $replacement .= '<input type="submit" value="'.$addcart.'" />';
485
+ }
486
+
487
+ $replacement .= '<input type="hidden" name="product" value="'.$name.'" /><input type="hidden" name="price" value="'.$price.'" /><input type="hidden" name="shipping" value="'.$shipping.'" /><input type="hidden" name="addcart" value="1" /><input type="hidden" name="cartLink" value="'.cart_current_page_url().'" /></form></object>';
488
+
489
+ return $replacement;
490
  }
491
 
492
  function cart_not_empty()
519
  return $pageURL;
520
  }
521
 
522
+ function show_wp_cart_options_page () {
523
+ $wp_simple_paypal_shopping_cart_version = "2.6";
524
+ if (isset($_POST['info_update']))
525
+ {
526
+ update_option('cart_payment_currency', (string)$_POST["cart_payment_currency"]);
527
+ update_option('cart_currency_symbol', (string)$_POST["cart_currency_symbol"]);
528
+ update_option('cart_base_shipping_cost', (string)$_POST["cart_base_shipping_cost"]);
529
+ update_option('cart_free_shipping_threshold', (string)$_POST["cart_free_shipping_threshold"]);
530
+ update_option('cart_paypal_email', (string)$_POST["cart_paypal_email"]);
531
+ update_option('addToCartButtonName', (string)$_POST["addToCartButtonName"]);
532
+ update_option('wp_cart_title', (string)$_POST["wp_cart_title"]);
533
+ update_option('wp_cart_empty_text', (string)$_POST["wp_cart_empty_text"]);
534
+ update_option('cart_return_from_paypal_url', (string)$_POST["cart_return_from_paypal_url"]);
535
+ update_option('cart_products_page_url', (string)$_POST["cart_products_page_url"]);
536
+ update_option('wp_shopping_cart_image_hide', ($_POST['wp_shopping_cart_image_hide']!='') ? 'checked="checked"':'' );
537
+ update_option('wp_use_aff_platform', ($_POST['wp_use_aff_platform']!='') ? 'checked="checked"':'' );
538
+
539
+ echo '<div id="message" class="updated fade">';
540
+ echo '<p><strong>Options Updated!</strong></p></div>';
541
+ }
542
 
543
  $defaultCurrency = get_option('cart_payment_currency');
544
  if (empty($defaultCurrency)) $defaultCurrency = 'USD';
546
  $defaultSymbol = get_option('cart_currency_symbol');
547
  if (empty($defaultSymbol)) $defaultSymbol = '$';
548
 
549
+ $baseShipping = get_option('cart_base_shipping_cost');
550
+ if (empty($baseShipping)) $baseShipping = 0;
551
+
552
+ $cart_free_shipping_threshold = get_option('cart_free_shipping_threshold');
553
+
554
  $defaultEmail = get_option('cart_paypal_email');
555
  if (empty($defaultEmail)) $defaultEmail = get_bloginfo('admin_email');
556
 
563
  //if (empty($title)) $title = 'Your Shopping Cart';
564
 
565
  $emptyCartText = get_option('wp_cart_empty_text');
566
+ $cart_products_page_url = get_option('cart_products_page_url');
567
+
568
  if (get_option('wp_shopping_cart_image_hide'))
569
  $wp_cart_image_hide = 'checked="checked"';
570
  else
571
  $wp_cart_image_hide = '';
572
+
573
+ if (get_option('wp_use_aff_platform'))
574
+ $wp_use_aff_platform = 'checked="checked"';
575
+ else
576
+ $wp_use_aff_platform = '';
577
+
578
  ?>
579
  <h2>Simple Paypal Shopping Cart Settings v <?php echo $wp_simple_paypal_shopping_cart_version; ?></h2>
580
 
581
+ <p>For information, updates and detailed documentation, please visit:<br />
582
  <a href="http://www.tipsandtricks-hq.com/?p=768">http://www.tipsandtricks-hq.com/?p=768</a></p>
583
 
584
  <fieldset class="options">
585
  <legend>Usage:</legend>
586
 
587
+ <p>1. To add the 'Add to Cart' button simply add the trigger text <strong>[wp_cart:PRODUCT-NAME:price:PRODUCT-PRICE:end]</strong> to a post or page next to the product. Replace PRODUCT-NAME and PRODUCT-PRICE with the actual name and price. For example: [wp_cart:Test Product:price:15.00:end]</p>
588
+ <p>2. To add the shopping cart to a post or page (eg. checkout page) simply add the shortcode <strong>[show_wp_shopping_cart]</strong> to a post or page or use the sidebar widget to add the shopping cart to the sidebar.</p>
589
  </fieldset>
590
+
591
+ <form method="post" action="<?php echo $_SERVER["REQUEST_URI"]; ?>">
592
+ <input type="hidden" name="info_update" id="info_update" value="true" />
593
  <?php
594
+ echo '
595
+ <div class="postbox">
596
+ <h3><label for="title">PayPal and Shopping Cart Settings</label></h3>
597
+ <div class="inside">';
598
+
599
+ echo '
600
  <table class="form-table">
601
  <tr valign="top">
602
  <th scope="row">Paypal Email Address</th>
603
+ <td><input type="text" name="cart_paypal_email" value="'.$defaultEmail.'" size="40" /></td>
604
  </tr>
605
  <tr valign="top">
606
  <th scope="row">Shopping Cart title</th>
607
+ <td><input type="text" name="wp_cart_title" value="'.$title.'" size="40" /></td>
608
  </tr>
609
  <tr valign="top">
610
  <th scope="row">Text to show when Cart empty</th>
611
+ <td><input type="text" name="wp_cart_empty_text" value="'.$emptyCartText.'" size="40" /></td>
612
  </tr>
613
  <tr valign="top">
614
  <th scope="row">Currency</th>
620
  </td>
621
  </tr>
622
 
623
+ <tr valign="top">
624
+ <th scope="row">Base Shipping Cost</th>
625
+ <td><input type="text" name="cart_base_shipping_cost" value="'.$baseShipping.'" size="5" /> <br />This is the base shipping cost that will be added to the total of individual products shipping cost. Put 0 if you do not want to charge shipping cost or use base shipping cost. <a href="http://www.tipsandtricks-hq.com/ecommerce/?p=297" target="_blank">Learn More on Shipping Calculation</a></td>
626
+ </tr>
627
+
628
+ <tr valign="top">
629
+ <th scope="row">Free Shipping for Orders Over</th>
630
+ <td><input type="text" name="cart_free_shipping_threshold" value="'.$cart_free_shipping_threshold.'" size="5" /> <br />When a customer orders more than this amount he/she will get free shipping. Leave empty if you do not want to use it.</td>
631
+ </tr>
632
+
633
  <tr valign="top">
634
  <th scope="row">Add to Cart button text or Image</th>
635
+ <td><input type="text" name="addToCartButtonName" value="'.$addcart.'" size="100" /><br />To use a cusomized image as the button simply enter the URL of the image file. eg. http://www.tipsandtricks-hq.com/wp-content/plugins/wordpress-paypal-shopping-cart/images/buy_now_button.png</td>
636
  </tr>
637
 
638
  <tr valign="top">
639
  <th scope="row">Return URL</th>
640
+ <td><input type="text" name="cart_return_from_paypal_url" value="'.$return_url.'" size="100" /><br />This is the URL the customer will be redirected to after a successful payment</td>
641
+ </tr>
642
+
643
+ <tr valign="top">
644
+ <th scope="row">Products Page URL</th>
645
+ <td><input type="text" name="cart_products_page_url" value="'.$cart_products_page_url.'" size="100" /><br />This is the URL of your products page if you have any. If used, the shopping cart widget will display a link to this page when cart is empty</td>
646
  </tr>
647
  </table>
648
 
649
+
650
  <table class="form-table">
651
  <tr valign="top">
652
  <th scope="row">Hide Shopping Cart Image</th>
653
  <td><input type="checkbox" name="wp_shopping_cart_image_hide" value="1" '.$wp_cart_image_hide.' /><br />If ticked the shopping cart image will no be shown.</td>
654
  </tr>
655
  </table>
 
 
 
 
 
 
656
 
657
+ <table class="form-table">
658
+ <tr valign="top">
659
+ <th scope="row">Use WP Affiliate Platform</th>
660
+ <td><input type="checkbox" name="wp_use_aff_platform" value="1" '.$wp_use_aff_platform.' /><br />Check this if using with the <a href="http://tipsandtricks-hq.com/?p=1474" target="_blank">WP Affiliate Platform plugin</a>.</td>
661
+ </tr>
662
+ </table>
663
+ </div></div>
664
+ <div class="submit">
665
+ <input type="submit" name="info_update" value="Update Options &raquo;" />
666
+ </div>
667
  </form>
668
  ';
669
+ echo 'Like the Simple WordPress Shopping Cart Plugin? <a href="http://wordpress.org/extend/plugins/wordpress-simple-paypal-shopping-cart" target="_blank">Give it a good rating</a>';
670
  }
671
 
672
  function wp_cart_options()
673
  {
674
  echo '<div class="wrap"><h2>WP Paypal Shopping Cart Options</h2>';
675
+ echo '<div id="poststuff"><div id="post-body">';
676
  show_wp_cart_options_page();
677
+ echo '</div></div>';
678
  echo '</div>';
679
  }
680
 
713
  wp_register_widget_control('wp_paypal_shopping_cart_widgets', __('WP Paypal Shopping Cart'), 'wp_paypal_shopping_cart_widget_control' );
714
  }
715
 
716
+ function wp_cart_css()
717
+ {
718
+ echo '<link type="text/css" rel="stylesheet" href="'.WP_CART_URL.'/wp_shopping_cart_style.css" />'."\n";
719
+ }
720
+
721
  // Insert the options page to the admin menu
722
  add_action('admin_menu','wp_cart_options_page');
 
723
  add_action('init', 'widget_wp_paypal_shopping_cart_init');
724
+ //add_filter('the_content', 'print_wp_cart_button',11);
725
 
726
+ add_filter('the_content', 'print_wp_cart_button_new',11);
 
727
  add_filter('the_content', 'shopping_cart_show');
728
 
729
+ add_shortcode('show_wp_shopping_cart', 'show_wp_shopping_cart_handler');
730
+
731
+ add_action('wp_head', 'wp_cart_css');
732
+ add_action('wp_head', 'wp_cart_add_read_form_javascript');
733
  ?>
wp_shopping_cart_style.css ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .shopping_cart{
2
+ font-size:12px;
3
+ }
4
+ .shopping_cart h2{
5
+ font-size:14px;
6
+ }
7
+
8
+ .wp_cart_checkout_button:hover{
9
+ opacity:0.7;
10
+ }
11
+
12
+ .wp_cart_button:hover{
13
+ opacity:0.7;
14
+ }
15
+