WordPress Simple PayPal Shopping Cart - Version 3.8.8

Version Description

  • Added a discount coupon feature to the shopping cart. You can now configure discount coupon via the Simple cart settings -> Coupon/Discount menu
  • View link now shows the order details
  • fixed a bug where the shipping price wasn't properly showing for more than $1000
  • WordPress 3.7 compatibility
Download this release

Release Info

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

Code changes from version 3.8.7 to 3.8.8

class-coupon.php ADDED
@@ -0,0 +1,136 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class WPSPSC_Coupons_Collection
3
+ {
4
+ var $coupon_items = array();
5
+
6
+ function WPSPSC_Coupons_Collection()
7
+ {
8
+
9
+ }
10
+
11
+ function add_coupon_item($coupon_item)
12
+ {
13
+ array_push($this->coupon_items, $coupon_item);
14
+ }
15
+
16
+ function find_coupon_by_code($coupon_code)
17
+ {
18
+ if(empty($this->coupon_items)){
19
+ echo "<br />Admin needs to configure some discount coupons before it can be used";
20
+ return new stdClass();
21
+ }
22
+ foreach($this->coupon_items as $key => $coupon)
23
+ {
24
+ if($coupon->coupon_code == $coupon_code){
25
+ return $coupon;
26
+ }
27
+ }
28
+ return new stdClass();
29
+ }
30
+
31
+ function delete_coupon_item_by_id($coupon_id)
32
+ {
33
+ $coupon_deleted = false;
34
+ foreach($this->coupon_items as $key => $coupon)
35
+ {
36
+ if($coupon->id == $coupon_id){
37
+ $coupon_deleted = true;
38
+ unset($this->coupon_items[$key]);
39
+ }
40
+ }
41
+ if($coupon_deleted){
42
+ $this->coupon_items = array_values($this->coupon_items);
43
+ WPSPSC_Coupons_Collection::save_object($this);
44
+ }
45
+ }
46
+
47
+ function print_coupons_collection()
48
+ {
49
+ foreach ($this->coupon_items as $item){
50
+ $item->print_coupon_item_details();
51
+ }
52
+ }
53
+
54
+ static function save_object($obj_to_save)
55
+ {
56
+ update_option('wpspsc_coupons_collection', $obj_to_save);
57
+ }
58
+
59
+ static function get_instance()
60
+ {
61
+ $obj = get_option('wpspsc_coupons_collection');
62
+ if($obj){
63
+ return $obj;
64
+ }else{
65
+ return new WPSPSC_Coupons_Collection();
66
+ }
67
+ }
68
+ }
69
+
70
+ class WPSPSC_COUPON_ITEM
71
+ {
72
+ var $id;
73
+ var $coupon_code;
74
+ var $discount_rate;
75
+
76
+ function WPSPSC_COUPON_ITEM($coupon_code, $discount_rate)
77
+ {
78
+ $this->id = uniqid();
79
+ $this->coupon_code = $coupon_code;
80
+ $this->discount_rate = $discount_rate;
81
+ }
82
+
83
+ function print_coupon_item_details()
84
+ {
85
+ echo "<br />Coupon ID: ".$this->id;
86
+ echo "<br />Coupon Code: ".$this->coupon_code;
87
+ echo "<br />Discount Amt: ".$this->discount_rate;
88
+ }
89
+ }
90
+
91
+ function wpspsc_apply_cart_discount($coupon_code)
92
+ {
93
+ $collection_obj = WPSPSC_Coupons_Collection::get_instance();
94
+ $coupon_item = $collection_obj->find_coupon_by_code($coupon_code);
95
+ if(!isset($coupon_item->id)){
96
+ $_SESSION['wpspsc_cart_action_msg'] = '<div class="wpspsc_error_message">'.__("Coupon code used does not exist!", "WSPSC").'</div>';
97
+ return;
98
+ }
99
+
100
+ if (isset($_SESSION['wpspsc_discount_applied_once']) && $_SESSION['wpspsc_discount_applied_once'] == '1'){
101
+ $_SESSION['wpspsc_cart_action_msg'] = '<div class="wpspsc_error_message">'.__("Discount can only be applied once per checkout!", "WSPSC").'</div>';
102
+ return;
103
+ }
104
+
105
+ //Apply the discount
106
+ $curr_symbol = get_option('cart_currency_symbol');
107
+ $discount_rate = $coupon_item->discount_rate;
108
+ $products = $_SESSION['simpleCart'];
109
+ $discount_total = 0;
110
+ foreach ($products as $key => $item)
111
+ {
112
+ if ($item['price'] > 0)
113
+ {
114
+ $item_discount = (($item['price_orig']*$discount_rate)/100);
115
+ $discount_total = $discount_total + $item_discount*$item['quantity'];
116
+ $item['price'] = $item['price_orig'] - $item_discount;
117
+ unset($products[$key]);
118
+ array_push($products, $item);
119
+ }
120
+ }
121
+ $_SESSION['simpleCart'] = $products;
122
+ $disct_amt_msg = print_payment_currency($discount_total, $curr_symbol);
123
+ $_SESSION['wpspsc_cart_action_msg'] = '<div class="wpspsc_success_message">'.__("Discount applied successfully! Total Discount: ", "WSPSC").$disct_amt_msg.'</div>';
124
+ $_SESSION['wpspsc_discount_applied_once'] = '1';
125
+ $_SESSION['wpspsc_applied_coupon_code'] = $coupon_code;
126
+ }
127
+
128
+ function wpspsc_reapply_discount_coupon_if_needed()
129
+ {
130
+ //Re-apply coupon to the cart if necessary (meaning a coupon was already applied to the cart when this item was modified.
131
+ if (isset($_SESSION['wpspsc_discount_applied_once']) && $_SESSION['wpspsc_discount_applied_once'] == '1'){
132
+ $coupon_code = $_SESSION['wpspsc_applied_coupon_code'];
133
+ unset($_SESSION['wpspsc_discount_applied_once']);
134
+ wpspsc_apply_cart_discount($coupon_code);
135
+ }
136
+ }
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: Ruhul Amin, Tips and Tricks HQ
3
  Donate link: http://www.tipsandtricks-hq.com
4
  Tags: cart, shopping cart, WordPress shopping cart, Paypal shopping cart, sell products, online shop, shop, e-commerce, wordpress ecommerce, wordpress store, store, PayPal cart widget, sell digital products, digital downloads, paypal, paypal cart, e-shop
5
  Requires at least: 3.0
6
- Tested up to: 3.6.1
7
- Stable tag: 3.8.7
8
  License: GPLv2 or later
9
 
10
  Very easy to use Simple WordPress Paypal Shopping Cart Plugin. Great for selling products online in one click from your WordPress site.
@@ -41,6 +41,8 @@ or
41
  * Collect special instructions from your customers on the PayPal checkout page.
42
  * The orders menu will show you all the orders that you have received from your site.
43
  * Ability to configure an email that will get sent to your buyers after they purchase your product.
 
 
44
  * Compatible with WordPress Multi-site Installation.
45
  * and more...
46
 
@@ -119,6 +121,12 @@ None
119
 
120
  == Changelog ==
121
 
 
 
 
 
 
 
122
  = 3.8.7 =
123
  - Changed a few function names and made them unique to reduce the chance of a function name conflict with another plugin.
124
  - Added a new option in the plugin so the purchased items of a transaction will be shown under orders menu
3
  Donate link: http://www.tipsandtricks-hq.com
4
  Tags: cart, shopping cart, WordPress shopping cart, Paypal shopping cart, sell products, online shop, shop, e-commerce, wordpress ecommerce, wordpress store, store, PayPal cart widget, sell digital products, digital downloads, paypal, paypal cart, e-shop
5
  Requires at least: 3.0
6
+ Tested up to: 3.7
7
+ Stable tag: 3.8.8
8
  License: GPLv2 or later
9
 
10
  Very easy to use Simple WordPress Paypal Shopping Cart Plugin. Great for selling products online in one click from your WordPress site.
41
  * Collect special instructions from your customers on the PayPal checkout page.
42
  * The orders menu will show you all the orders that you have received from your site.
43
  * Ability to configure an email that will get sent to your buyers after they purchase your product.
44
+ * Ability to configure discount coupons.
45
+ * You can create coupons and give to your customers. When they use coupons during the checkout they will receive a discount.
46
  * Compatible with WordPress Multi-site Installation.
47
  * and more...
48
 
121
 
122
  == Changelog ==
123
 
124
+ = 3.8.8 =
125
+ - Added a discount coupon feature to the shopping cart. You can now configure discount coupon via the Simple cart settings -> Coupon/Discount menu
126
+ - View link now shows the order details
127
+ - fixed a bug where the shipping price wasn't properly showing for more than $1000
128
+ - WordPress 3.7 compatibility
129
+
130
  = 3.8.7 =
131
  - Changed a few function names and made them unique to reduce the chance of a function name conflict with another plugin.
132
  - Added a new option in the plugin so the purchased items of a transaction will be shown under orders menu
wp_shopping_cart.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
  /*
3
  Plugin Name: WP Simple Paypal Shopping cart
4
- Version: v3.8.7
5
  Plugin URI: http://www.tipsandtricks-hq.com/?p=768
6
  Author: Ruhul Amin
7
  Author URI: http://www.tipsandtricks-hq.com/
@@ -12,7 +12,7 @@ if(!isset($_SESSION)){
12
  session_start();
13
  }
14
 
15
- define('WP_CART_VERSION', '3.8.7');
16
  define('WP_CART_FOLDER', dirname(plugin_basename(__FILE__)));
17
  define('WP_CART_PATH',plugin_dir_path( __FILE__ ));
18
  define('WP_CART_URL', plugins_url('',__FILE__));
@@ -26,6 +26,7 @@ load_plugin_textdomain('WSPSC', false, WP_CART_FOLDER . '/languages');
26
  include_once('wp_shopping_cart_shortcodes.php');
27
  include_once('wp_shopping_cart_misc_functions.php');
28
  include_once('wp_shopping_cart_orders.php');
 
29
 
30
  function always_show_cart_handler($atts)
31
  {
@@ -62,61 +63,46 @@ if (isset($_REQUEST["reset_wp_cart"]) && !empty($_REQUEST["reset_wp_cart"]))
62
  reset_wp_cart();
63
  }
64
 
65
- // Reset the Cart as this is a returned customer from Paypal
66
- if (isset($_GET["merchant_return_link"]) && !empty($_GET["merchant_return_link"]))
67
- {
68
- reset_wp_cart();
69
- header('Location: ' . get_option('cart_return_from_paypal_url'));
70
- }
71
-
72
- if (isset($_GET["mc_gross"])&& $_GET["mc_gross"]> 0)
73
- {
74
- reset_wp_cart();
75
- header('Location: ' . get_option('cart_return_from_paypal_url'));
76
- }
77
-
78
  //Clear the cart if the customer landed on the thank you page
79
  if (get_option('wp_shopping_cart_reset_after_redirection_to_return_page'))
80
  {
81
- if(get_option('cart_return_from_paypal_url') == cart_current_page_url())
82
- {
83
- reset_wp_cart();
84
- }
85
  }
86
 
87
  function reset_wp_cart()
88
  {
89
  $products = $_SESSION['simpleCart'];
90
- if(empty($products))
91
- {
92
- unset($_SESSION['simpleCart']);
93
- unset($_SESSION['simple_cart_id']);
94
- return;
95
- }
96
  foreach ($products as $key => $item)
97
  {
98
  unset($products[$key]);
99
  }
100
- $_SESSION['simpleCart'] = $products;
101
  unset($_SESSION['simple_cart_id']);
 
 
 
102
  }
103
 
104
  function wpspc_cart_actions_handler()
105
  {
 
106
  if (isset($_POST['addcart']))
107
  {
108
- $domain_url = $_SERVER['SERVER_NAME'];
109
- $cookie_domain = str_replace("www","",$domain_url);
110
- setcookie("cart_in_use","true",time()+21600,"/",$cookie_domain); //useful to not serve cached page when using with a caching plugin
111
-
112
- //sanitize data
113
- $_POST['product'] = strip_tags($_POST['product']);//for PHP5.2 use filter_var($_POST['product'], FILTER_SANITIZE_STRING);
114
- $_POST['item_number'] = strip_tags($_POST['item_number']);
115
- if(isset($_POST['price']))$_POST['price'] = strip_tags($_POST['price']);
116
- isset($_POST['shipping'])?$_POST['shipping'] = strip_tags($_POST['shipping']):$_POST['shipping']='';
117
- isset($_POST['cartLink'])?$_POST['cartLink'] = strip_tags($_POST['cartLink']):$_POST['cartLink']='';
118
-
119
- $count = 1;
120
  $products = $_SESSION['simpleCart'];
121
  if (is_array($products))
122
  {
@@ -145,13 +131,13 @@ function wpspc_cart_actions_handler()
145
  $price = $_POST['price'];
146
  }
147
 
148
- $default_cur_symbol = get_option('cart_currency_symbol');
149
- $price = str_replace($default_cur_symbol,"",$price);
150
 
151
- $shipping = $_POST['shipping'];
152
- $shipping = str_replace($default_cur_symbol,"",$shipping);
153
 
154
- $product = array('name' => stripslashes($_POST['product']), 'price' => $price, 'quantity' => $count, 'shipping' => $shipping, 'cartLink' => $_POST['cartLink'], 'item_number' => $_POST['item_number']);
155
  if(isset($_POST['file_url']) && !empty($_POST['file_url'])){
156
  $file_url = strip_tags($_POST['file_url']);
157
  $product['file_url'] = $file_url;
@@ -161,6 +147,9 @@ function wpspc_cart_actions_handler()
161
 
162
  sort($products);
163
  $_SESSION['simpleCart'] = $products;
 
 
 
164
  if(!isset($_SESSION['simple_cart_id']) && empty($_SESSION['simple_cart_id']))
165
  {
166
  wpspc_insert_new_record();
@@ -204,11 +193,15 @@ function wpspc_cart_actions_handler()
204
  unset($products[$key]);
205
  array_push($products, $item);
206
  }
207
- else if (($item['name'] == stripslashes($_POST['product'])) && !$_POST['quantity'])
208
  unset($products[$key]);
 
209
  }
210
  sort($products);
211
  $_SESSION['simpleCart'] = $products;
 
 
 
212
  if(isset($_SESSION['simple_cart_id']) && !empty($_SESSION['simple_cart_id']))
213
  {
214
  wpspc_update_cart_items_record();
@@ -220,13 +213,24 @@ function wpspc_cart_actions_handler()
220
  foreach ($products as $key => $item)
221
  {
222
  if ($item['name'] == stripslashes($_POST['product']))
223
- unset($products[$key]);
224
  }
225
  $_SESSION['simpleCart'] = $products;
 
 
 
226
  if(isset($_SESSION['simple_cart_id']) && !empty($_SESSION['simple_cart_id']))
227
  {
228
  wpspc_update_cart_items_record();
229
  }
 
 
 
 
 
 
 
 
230
  }
231
  }
232
 
@@ -353,7 +357,7 @@ function print_wp_shopping_cart()
353
 
354
  $form .= "
355
  <input type=\"hidden\" name=\"item_name_$count\" value=\"".$item['name']."\" />
356
- <input type=\"hidden\" name=\"amount_$count\" value='".number_format($item['price'],2)."' />
357
  <input type=\"hidden\" name=\"quantity_$count\" value=\"".$item['quantity']."\" />
358
  <input type='hidden' name='item_number' value='".$item['item_number']."' />
359
  ";
@@ -361,7 +365,7 @@ function print_wp_shopping_cart()
361
  }
362
  if (!get_option('wp_shopping_cart_use_profile_shipping'))
363
  {
364
- $postage_cost = number_format($postage_cost,2);
365
  $form .= "<input type=\"hidden\" name=\"shipping_1\" value='".$postage_cost."' />"; //You can also use "handling_cart" variable to use shipping and handling here
366
  }
367
  if (get_option('wp_shopping_cart_collect_address'))//force address collection
@@ -374,8 +378,6 @@ function print_wp_shopping_cart()
374
 
375
  if ($count)
376
  {
377
- //$output .= '<tr><td></td><td></td><td></td></tr>';
378
-
379
  if ($postage_cost != 0)
380
  {
381
  $output .= "
@@ -383,39 +385,52 @@ function print_wp_shopping_cart()
383
  <tr><td colspan='2' style='font-weight: bold; text-align: right;'>".(__("Shipping", "WSPSC")).": </td><td style='text-align: center'>".print_payment_currency($postage_cost, $paypal_symbol, $decimal)."</td><td></td></tr>";
384
  }
385
 
386
- $output .= "
387
- <tr><td colspan='2' style='font-weight: bold; text-align: right;'>".(__("Total", "WSPSC")).": </td><td style='text-align: center'>".print_payment_currency(($total+$postage_cost), $paypal_symbol, $decimal)."</td><td></td></tr>
388
- <tr><td colspan='4'>";
389
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
390
  $paypal_checkout_url = WP_CART_LIVE_PAYPAL_URL;
391
  if (get_option('wp_shopping_cart_enable_sandbox')){
392
  $paypal_checkout_url = WP_CART_SANDBOX_PAYPAL_URL;
393
  }
394
- $output .= '<form action="'.$paypal_checkout_url.'" method="post">'.$form;
395
- if ($count)
396
- $output .= '<input type="image" src="'.WP_CART_URL.'/images/'.(__("paypal_checkout_EN.png", "WSPSC")).'" name="submit" class="wp_cart_checkout_button" alt="'.(__("Make payments with PayPal - it\'s fast, free and secure!", "WSPSC")).'" />';
397
-
398
- $output .= $urls.'
399
- <input type="hidden" name="business" value="'.$email.'" />
400
- <input type="hidden" name="currency_code" value="'.$paypal_currency.'" />
401
- <input type="hidden" name="cmd" value="_cart" />
402
- <input type="hidden" name="upload" value="1" />
403
- <input type="hidden" name="rm" value="2" />
404
- <input type="hidden" name="charset" value="utf-8" />
405
- <input type="hidden" name="mrb" value="3FWGC6LFTMTUG" />';
406
- $wp_cart_note_to_seller_text = get_option('wp_cart_note_to_seller_text');
407
- if(!empty($wp_cart_note_to_seller_text)){
408
- $output .= '<input type="hidden" name="no_note" value="0" /><input type="hidden" name="cn" value="'.$wp_cart_note_to_seller_text.'" />';
409
- }
410
-
411
- $output .= wp_cart_add_custom_field();
412
- $output .= '</form>';
 
 
 
413
  }
414
- $output .= "
415
- </td></tr>
416
- </table></div>
417
- ";
418
-
419
  return $output;
420
  }
421
 
@@ -673,7 +688,7 @@ function cart_not_empty()
673
  return 0;
674
  }
675
 
676
- function print_payment_currency($price, $symbol, $decimal)
677
  {
678
  return $symbol.number_format($price, 2, $decimal, ',');
679
  }
@@ -703,7 +718,7 @@ function simple_cart_total()
703
  $item_total_shipping += $item['shipping'] * $item['quantity'];
704
  }
705
  $grand_total = $total + $item_total_shipping;
706
- return number_format($grand_total,2);
707
  }
708
 
709
  // Handle the options page display
1
  <?php
2
  /*
3
  Plugin Name: WP Simple Paypal Shopping cart
4
+ Version: v3.8.8
5
  Plugin URI: http://www.tipsandtricks-hq.com/?p=768
6
  Author: Ruhul Amin
7
  Author URI: http://www.tipsandtricks-hq.com/
12
  session_start();
13
  }
14
 
15
+ define('WP_CART_VERSION', '3.8.8');
16
  define('WP_CART_FOLDER', dirname(plugin_basename(__FILE__)));
17
  define('WP_CART_PATH',plugin_dir_path( __FILE__ ));
18
  define('WP_CART_URL', plugins_url('',__FILE__));
26
  include_once('wp_shopping_cart_shortcodes.php');
27
  include_once('wp_shopping_cart_misc_functions.php');
28
  include_once('wp_shopping_cart_orders.php');
29
+ include_once('class-coupon.php');
30
 
31
  function always_show_cart_handler($atts)
32
  {
63
  reset_wp_cart();
64
  }
65
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
  //Clear the cart if the customer landed on the thank you page
67
  if (get_option('wp_shopping_cart_reset_after_redirection_to_return_page'))
68
  {
69
+ if(get_option('cart_return_from_paypal_url') == cart_current_page_url())
70
+ {
71
+ reset_wp_cart();
72
+ }
73
  }
74
 
75
  function reset_wp_cart()
76
  {
77
  $products = $_SESSION['simpleCart'];
 
 
 
 
 
 
78
  foreach ($products as $key => $item)
79
  {
80
  unset($products[$key]);
81
  }
82
+ $_SESSION['simpleCart'] = $products;
83
  unset($_SESSION['simple_cart_id']);
84
+ unset($_SESSION['wpspsc_cart_action_msg']);
85
+ unset($_SESSION['wpspsc_discount_applied_once']);
86
+ unset($_SESSION['wpspsc_applied_coupon_code']);
87
  }
88
 
89
  function wpspc_cart_actions_handler()
90
  {
91
+ unset($_SESSION['wpspsc_cart_action_msg']);
92
  if (isset($_POST['addcart']))
93
  {
94
+ $domain_url = $_SERVER['SERVER_NAME'];
95
+ $cookie_domain = str_replace("www","",$domain_url);
96
+ setcookie("cart_in_use","true",time()+21600,"/",$cookie_domain); //useful to not serve cached page when using with a caching plugin
97
+
98
+ //sanitize data
99
+ $_POST['product'] = strip_tags($_POST['product']);//for PHP5.2 use filter_var($_POST['product'], FILTER_SANITIZE_STRING);
100
+ $_POST['item_number'] = strip_tags($_POST['item_number']);
101
+ if(isset($_POST['price']))$_POST['price'] = strip_tags($_POST['price']);
102
+ isset($_POST['shipping'])?$_POST['shipping'] = strip_tags($_POST['shipping']):$_POST['shipping']='';
103
+ isset($_POST['cartLink'])?$_POST['cartLink'] = strip_tags($_POST['cartLink']):$_POST['cartLink']='';
104
+
105
+ $count = 1;
106
  $products = $_SESSION['simpleCart'];
107
  if (is_array($products))
108
  {
131
  $price = $_POST['price'];
132
  }
133
 
134
+ $default_cur_symbol = get_option('cart_currency_symbol');
135
+ $price = str_replace($default_cur_symbol,"",$price);
136
 
137
+ $shipping = $_POST['shipping'];
138
+ $shipping = str_replace($default_cur_symbol,"",$shipping);
139
 
140
+ $product = array('name' => stripslashes($_POST['product']), 'price' => $price, 'price_orig' =>$price, 'quantity' => $count, 'shipping' => $shipping, 'cartLink' => $_POST['cartLink'], 'item_number' => $_POST['item_number']);
141
  if(isset($_POST['file_url']) && !empty($_POST['file_url'])){
142
  $file_url = strip_tags($_POST['file_url']);
143
  $product['file_url'] = $file_url;
147
 
148
  sort($products);
149
  $_SESSION['simpleCart'] = $products;
150
+
151
+ wpspsc_reapply_discount_coupon_if_needed();//Re-apply coupon to the cart if necessary
152
+
153
  if(!isset($_SESSION['simple_cart_id']) && empty($_SESSION['simple_cart_id']))
154
  {
155
  wpspc_insert_new_record();
193
  unset($products[$key]);
194
  array_push($products, $item);
195
  }
196
+ else if (($item['name'] == stripslashes($_POST['product'])) && !$_POST['quantity']){
197
  unset($products[$key]);
198
+ }
199
  }
200
  sort($products);
201
  $_SESSION['simpleCart'] = $products;
202
+
203
+ wpspsc_reapply_discount_coupon_if_needed();//Re-apply coupon to the cart if necessary
204
+
205
  if(isset($_SESSION['simple_cart_id']) && !empty($_SESSION['simple_cart_id']))
206
  {
207
  wpspc_update_cart_items_record();
213
  foreach ($products as $key => $item)
214
  {
215
  if ($item['name'] == stripslashes($_POST['product']))
216
+ unset($products[$key]);
217
  }
218
  $_SESSION['simpleCart'] = $products;
219
+
220
+ wpspsc_reapply_discount_coupon_if_needed();//Re-apply coupon to the cart if necessary
221
+
222
  if(isset($_SESSION['simple_cart_id']) && !empty($_SESSION['simple_cart_id']))
223
  {
224
  wpspc_update_cart_items_record();
225
  }
226
+ if(count($_SESSION['simpleCart']) < 1){
227
+ reset_wp_cart();
228
+ }
229
+ }
230
+ else if(isset($_POST['wpspsc_coupon_code']))
231
+ {
232
+ $coupon_code = strip_tags($_POST['wpspsc_coupon_code']);
233
+ wpspsc_apply_cart_discount($coupon_code);
234
  }
235
  }
236
 
357
 
358
  $form .= "
359
  <input type=\"hidden\" name=\"item_name_$count\" value=\"".$item['name']."\" />
360
+ <input type=\"hidden\" name=\"amount_$count\" value='".wpspsc_number_format_price($item['price'])."' />
361
  <input type=\"hidden\" name=\"quantity_$count\" value=\"".$item['quantity']."\" />
362
  <input type='hidden' name='item_number' value='".$item['item_number']."' />
363
  ";
365
  }
366
  if (!get_option('wp_shopping_cart_use_profile_shipping'))
367
  {
368
+ $postage_cost = wpspsc_number_format_price($postage_cost);
369
  $form .= "<input type=\"hidden\" name=\"shipping_1\" value='".$postage_cost."' />"; //You can also use "handling_cart" variable to use shipping and handling here
370
  }
371
  if (get_option('wp_shopping_cart_collect_address'))//force address collection
378
 
379
  if ($count)
380
  {
 
 
381
  if ($postage_cost != 0)
382
  {
383
  $output .= "
385
  <tr><td colspan='2' style='font-weight: bold; text-align: right;'>".(__("Shipping", "WSPSC")).": </td><td style='text-align: center'>".print_payment_currency($postage_cost, $paypal_symbol, $decimal)."</td><td></td></tr>";
386
  }
387
 
388
+ $output .= "<tr><td colspan='2' style='font-weight: bold; text-align: right;'>".(__("Total", "WSPSC")).": </td><td style='text-align: center'>".print_payment_currency(($total+$postage_cost), $paypal_symbol, $decimal)."</td><td></td></tr>";
389
+
390
+ if(isset($_SESSION['wpspsc_cart_action_msg']) && !empty($_SESSION['wpspsc_cart_action_msg'])){
391
+ $output .= '<tr><td colspan="4"><span class="wpspsc_cart_action_msg">'.$_SESSION['wpspsc_cart_action_msg'].'</span></td></tr>';
392
+ }
393
+
394
+ if (get_option('wpspsc_enable_coupon') == '1'){
395
+ $output .= '<tr><td colspan="4">
396
+ <div class="wpspsc_coupon_section">
397
+ <span class="wpspsc_coupon_label">'.(__("Enter Coupon Code", "WSPSC")).'</span>
398
+ <form method="post" action="" >
399
+ <input type="text" name="wpspsc_coupon_code" value="" size="10" />
400
+ <span class="wpspsc_coupon_apply_button"><input type="submit" name="wpspsc_apply_coupon" class="wpspsc_apply_coupon" value="'.(__("Apply", "WSPSC")).'" /></span>
401
+ </form>
402
+ </div>
403
+ </td></tr>';
404
+ }
405
+
406
  $paypal_checkout_url = WP_CART_LIVE_PAYPAL_URL;
407
  if (get_option('wp_shopping_cart_enable_sandbox')){
408
  $paypal_checkout_url = WP_CART_SANDBOX_PAYPAL_URL;
409
  }
410
+
411
+ $output .= "<tr class='wpspsc_checkout_form'><td colspan='4'>";
412
+ $output .= '<form action="'.$paypal_checkout_url.'" method="post">'.$form;
413
+ if ($count)
414
+ $output .= '<input type="image" src="'.WP_CART_URL.'/images/'.(__("paypal_checkout_EN.png", "WSPSC")).'" name="submit" class="wp_cart_checkout_button" alt="'.(__("Make payments with PayPal - it\'s fast, free and secure!", "WSPSC")).'" />';
415
+
416
+ $output .= $urls.'
417
+ <input type="hidden" name="business" value="'.$email.'" />
418
+ <input type="hidden" name="currency_code" value="'.$paypal_currency.'" />
419
+ <input type="hidden" name="cmd" value="_cart" />
420
+ <input type="hidden" name="upload" value="1" />
421
+ <input type="hidden" name="rm" value="2" />
422
+ <input type="hidden" name="charset" value="utf-8" />
423
+ <input type="hidden" name="mrb" value="3FWGC6LFTMTUG" />';
424
+ $wp_cart_note_to_seller_text = get_option('wp_cart_note_to_seller_text');
425
+ if(!empty($wp_cart_note_to_seller_text)){
426
+ $output .= '<input type="hidden" name="no_note" value="0" /><input type="hidden" name="cn" value="'.$wp_cart_note_to_seller_text.'" />';
427
+ }
428
+
429
+ $output .= wp_cart_add_custom_field();
430
+ $output .= '</form>';
431
+ $output .= '</td></tr>';
432
  }
433
+ $output .= "</table></div>";
 
 
 
 
434
  return $output;
435
  }
436
 
688
  return 0;
689
  }
690
 
691
+ function print_payment_currency($price, $symbol, $decimal='.')
692
  {
693
  return $symbol.number_format($price, 2, $decimal, ',');
694
  }
718
  $item_total_shipping += $item['shipping'] * $item['quantity'];
719
  }
720
  $grand_total = $total + $item_total_shipping;
721
+ return wpspsc_number_format_price($grand_total);
722
  }
723
 
724
  // Handle the options page display
wp_shopping_cart_discounts_menu.php ADDED
@@ -0,0 +1,175 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ function show_wp_cart_coupon_discount_settings_page()
4
+ {
5
+ if (isset($_POST['wpspsc_coupon_settings']))
6
+ {
7
+ $nonce = $_REQUEST['_wpnonce'];
8
+ if ( !wp_verify_nonce($nonce, 'wpspsc_coupon_settings')){
9
+ wp_die('Error! Nonce Security Check Failed! Go back to Coupon/Discount menu and save the settings again.');
10
+ }
11
+ update_option('wpspsc_enable_coupon', ($_POST['wpspsc_enable_coupon']=='1') ? '1':'');
12
+ echo '<div id="message" class="updated fade"><p><strong>';
13
+ echo 'Coupon Settings Updated!';
14
+ echo '</strong></p></div>';
15
+ }
16
+ if (isset($_POST['wpspsc_save_coupon']))
17
+ {
18
+ $nonce = $_REQUEST['_wpnonce'];
19
+ if ( !wp_verify_nonce($nonce, 'wpspsc_save_coupon')){
20
+ wp_die('Error! Nonce Security Check Failed! Go back to email settings menu and save the settings again.');
21
+ }
22
+
23
+ $collection_obj = WPSPSC_Coupons_Collection::get_instance();
24
+ $coupon_code = trim(stripcslashes($_POST["wpspsc_coupon_code"]));
25
+ $discount_rate = trim($_POST["wpspsc_coupon_rate"]);
26
+ $coupon_item = new WPSPSC_COUPON_ITEM($coupon_code, $discount_rate);
27
+ $collection_obj->add_coupon_item($coupon_item);
28
+ WPSPSC_Coupons_Collection::save_object($collection_obj);
29
+
30
+ echo '<div id="message" class="updated fade"><p><strong>';
31
+ echo 'Coupon Saved!';
32
+ echo '</strong></p></div>';
33
+ }
34
+
35
+ if(isset($_REQUEST['wpspsc_delete_coupon_id']))
36
+ {
37
+ $coupon_id = $_REQUEST['wpspsc_delete_coupon_id'];
38
+ $collection_obj = WPSPSC_Coupons_Collection::get_instance();
39
+ $collection_obj->delete_coupon_item_by_id($coupon_id);
40
+ echo '<div id="message" class="updated fade"><p>';
41
+ echo 'Coupon successfully deleted!';
42
+ echo '</p></div>';
43
+ }
44
+ $wpspsc_enable_coupon = '';
45
+ if (get_option('wpspsc_enable_coupon') == '1'){
46
+ $wpspsc_enable_coupon = 'checked="checked"';
47
+ }
48
+ ?>
49
+
50
+ <div style="background: none repeat scroll 0 0 #FFF6D5;border: 1px solid #D1B655;color: #3F2502;margin: 10px 0;padding: 5px 5px 5px 10px;text-shadow: 1px 1px #FFFFFF;">
51
+ <p><?php _e("For more information, updates, detailed documentation and video tutorial, please visit:", "WSPSC"); ?><br />
52
+ <a href="http://www.tipsandtricks-hq.com/wordpress-simple-paypal-shopping-cart-plugin-768" target="_blank"><?php _e("WP Simple Cart Homepage", "WSPSC"); ?></a></p>
53
+ </div>
54
+
55
+ <form method="post" action="<?php echo $_SERVER["REQUEST_URI"]; ?>">
56
+ <?php wp_nonce_field('wpspsc_coupon_settings'); ?>
57
+ <input type="hidden" name="coupon_settings_update" id="coupon_settings_update" value="true" />
58
+
59
+ <div class="postbox">
60
+ <h3><label for="title">Coupon/Discount Settings</label></h3>
61
+ <div class="inside">
62
+
63
+ <form method="post" action="">
64
+ <table class="form-table" width="100%" border="0" cellspacing="0" cellpadding="6">
65
+
66
+ <tr valign="top">
67
+ <th scope="row">Enable Discount Coupon Feature</th>
68
+ <td>
69
+ <input type="checkbox" name="wpspsc_enable_coupon" value="1" <?php echo $wpspsc_enable_coupon; ?> />
70
+ <span class="description"> When checked your customers will be able to enter a coupon code in the shopping cart before checkout.</span>
71
+ </td>
72
+ </tr>
73
+
74
+ <tr valign="top">
75
+ <th scope="row">
76
+ <div class="submit">
77
+ <input type="submit" name="wpspsc_coupon_settings" class="button-primary" value="<?php echo (__("Update &raquo;", "WSPSC")) ?>" />
78
+ </div>
79
+ </th>
80
+ <td></td>
81
+ </tr>
82
+
83
+ </table>
84
+
85
+ </form>
86
+ </div></div>
87
+
88
+ <form method="post" action="<?php echo $_SERVER["REQUEST_URI"]; ?>">
89
+ <?php wp_nonce_field('wpspsc_save_coupon'); ?>
90
+ <input type="hidden" name="info_update" id="info_update" value="true" />
91
+
92
+ <div class="postbox">
93
+ <h3><label for="title">Add Coupon/Discount</label></h3>
94
+ <div class="inside">
95
+
96
+ <form method="post" action="">
97
+ <table class="form-table" border="0" cellspacing="0" cellpadding="6" style="max-width:600px;">
98
+
99
+ <tr valign="top">
100
+
101
+ <td width="25%" align="left">
102
+ Coupon Code<br />
103
+ <input name="wpspsc_coupon_code" type="text" size="15" value=""/>
104
+ </td>
105
+
106
+ <td width="25%" align="left">
107
+ Discount Rate (%)<br />
108
+ <input name="wpspsc_coupon_rate" type="text" size="7" value=""/>
109
+ </td>
110
+
111
+ <td width="25%" align="left">
112
+ <div class="submit">
113
+ <input type="submit" name="wpspsc_save_coupon" class="button-primary" value="<?php echo (__("Save Coupon &raquo;", "WSPSC")) ?>" />
114
+ </div>
115
+ </td>
116
+
117
+ </tr>
118
+
119
+ </table>
120
+
121
+ </form>
122
+ </div></div>
123
+
124
+ <?php
125
+
126
+ //display table
127
+ $output = "";
128
+ $output .= '
129
+ <table class="widefat" style="max-width:800px;">
130
+ <thead><tr>
131
+ <th scope="col">Coupon Code</th>
132
+ <th scope="col">Discount Rate (%)</th>
133
+ <th scope="col"></th>
134
+ </tr></thead>
135
+ <tbody>';
136
+
137
+ $collection_obj = WPSPSC_Coupons_Collection::get_instance();
138
+ if($collection_obj)
139
+ {
140
+ $coupons = $collection_obj->coupon_items;
141
+ $number_of_coupons = count($coupons);
142
+ if($number_of_coupons > 0)
143
+ {
144
+ foreach ($coupons as $coupon)
145
+ {
146
+ $output .= '<tr>';
147
+ $output .= '<td><strong>'.$coupon->coupon_code.'</strong></td>';
148
+ $output .= '<td><strong>'.$coupon->discount_rate.'</strong></td>';
149
+ $output .= '<td>';
150
+ $output .= "<form method=\"post\" action=\"\" onSubmit=\"return confirm('Are you sure you want to delete this entry?');\">";
151
+ $output .= "<input type=\"hidden\" name=\"wpspsc_delete_coupon_id\" value=".$coupon->id." />";
152
+ $output .= '<input style="border: none; background-color: transparent; padding: 0; cursor:pointer;" type="submit" name="Delete" value="Delete">';
153
+ $output .= "</form>";
154
+ $output .= '</td>';
155
+ $output .= '</tr>';
156
+ $row_count = $row_count + 1;
157
+ }
158
+ }
159
+ else
160
+ {
161
+ $output .= '<tr><td colspan="5">No Coupons Configured.</td></tr>';
162
+ }
163
+ }
164
+ else
165
+ {
166
+ $output .= '<tr><td colspan="5">No Record found</td></tr>';
167
+ }
168
+
169
+ $output .= '</tbody>
170
+ </table>';
171
+
172
+ //$output .= '<p><a href="options-general.php?page=wordpress-paypal-shopping-cart&action=discount-settings">Add New</a></p>';
173
+ echo $output;
174
+ }
175
+
wp_shopping_cart_misc_functions.php CHANGED
@@ -1,10 +1,10 @@
1
  <?php
2
 
3
  /* TODO
4
- - Change some of the INPUT name to make it more unique - http://wordpress.org/support/topic/checkout-functions-return-404-error-all-of-the-sudden
5
  - add a "button_image" parameter in the shortcode to customize the add to cart button
6
  - add an option for the admin email notification.
7
- - Simple discount coupons option (see the user submitted coupon code version and incorporate that in here)
8
  - Mention the available languages
9
  */
10
 
@@ -34,6 +34,12 @@ function wp_cart_admin_init_handler()
34
  wpspc_add_meta_boxes();
35
  }
36
 
 
 
 
 
 
 
37
  function wpc_append_values_to_custom_field($name,$value)
38
  {
39
  $custom_field_val = $_SESSION['wp_cart_custom_values'];
@@ -161,5 +167,4 @@ function wpspc_run_activation()
161
  $email_body .= "\nThank you for your purchase! You ordered the following item(s):\n";
162
  $email_body .= "\n{product_details}";
163
  add_option('wpspc_buyer_email_body', $email_body);
164
-
165
- }
1
  <?php
2
 
3
  /* TODO
4
+ - After processing an IPN, call a function to clear all trash orders that are older than 6 hours.
5
  - add a "button_image" parameter in the shortcode to customize the add to cart button
6
  - add an option for the admin email notification.
7
+ - add a reset cart button
8
  - Mention the available languages
9
  */
10
 
34
  wpspc_add_meta_boxes();
35
  }
36
 
37
+ function wpspsc_number_format_price($price)
38
+ {
39
+ $formatted_num = number_format($price,2,'.','');
40
+ return $formatted_num;
41
+ }
42
+
43
  function wpc_append_values_to_custom_field($name,$value)
44
  {
45
  $custom_field_val = $_SESSION['wp_cart_custom_values'];
167
  $email_body .= "\nThank you for your purchase! You ordered the following item(s):\n";
168
  $email_body .= "\n{product_details}";
169
  add_option('wpspc_buyer_email_body', $email_body);
170
+ }
 
wp_shopping_cart_orders.php CHANGED
@@ -176,3 +176,11 @@ function wpspc_populate_order_columns($column, $post_id)
176
  }
177
  }
178
 
 
 
 
 
 
 
 
 
176
  }
177
  }
178
 
179
+ function wpspsc_customize_order_link( $permalink, $post ) {
180
+ if( $post->post_type == 'wpsc_cart_orders' ) { // assuming the post type is video
181
+ $permalink = get_admin_url().'post.php?post='.$post->ID.'&action=edit';
182
+ }
183
+ return $permalink;
184
+ }
185
+ add_filter('post_type_link',"wpspsc_customize_order_link",10,2);
186
+
wp_shopping_cart_settings.php CHANGED
@@ -4,7 +4,8 @@ function wp_cart_options()
4
  {
5
  $wpspc_plugin_tabs = array(
6
  'wordpress-paypal-shopping-cart' => 'General Settings',
7
- 'wordpress-paypal-shopping-cart&action=email-settings' => 'Email Settings'
 
8
  );
9
  echo '<div class="wrap">'.screen_icon( ).'<h2>'.(__("WP Paypal Shopping Cart Options", "WSPSC")).'</h2>';
10
  $current = "";
@@ -34,6 +35,10 @@ function wp_cart_options()
34
  case 'email-settings':
35
  show_wp_cart_email_settings_page();
36
  break;
 
 
 
 
37
  default:
38
  show_wp_cart_options_page();
39
  break;
4
  {
5
  $wpspc_plugin_tabs = array(
6
  'wordpress-paypal-shopping-cart' => 'General Settings',
7
+ 'wordpress-paypal-shopping-cart&action=email-settings' => 'Email Settings',
8
+ 'wordpress-paypal-shopping-cart&action=discount-settings' => 'Coupon/Discount'
9
  );
10
  echo '<div class="wrap">'.screen_icon( ).'<h2>'.(__("WP Paypal Shopping Cart Options", "WSPSC")).'</h2>';
11
  $current = "";
35
  case 'email-settings':
36
  show_wp_cart_email_settings_page();
37
  break;
38
+ case 'discount-settings':
39
+ include_once ('wp_shopping_cart_discounts_menu.php');
40
+ show_wp_cart_coupon_discount_settings_page();
41
+ break;
42
  default:
43
  show_wp_cart_options_page();
44
  break;
wp_shopping_cart_style.css CHANGED
@@ -24,6 +24,15 @@ opacity:0.7;
24
  margin: 0;
25
  }
26
 
 
 
 
 
 
 
 
 
 
27
  /* product display specific CSS */
28
  .wp_cart_product_display_box{
29
  border: 1px solid #E8E5DC;
24
  margin: 0;
25
  }
26
 
27
+ .wpspsc_error_message{
28
+ color:red !important;
29
+ font-weight:bold;
30
+ }
31
+ .wpspsc_success_message{
32
+ color:green !important;
33
+ font-weight:bold;
34
+ }
35
+
36
  /* product display specific CSS */
37
  .wp_cart_product_display_box{
38
  border: 1px solid #E8E5DC;