WooCommerce Direct Checkout - Version 1.0.5

Version Description

  • Updated "Add to cart" filter with WooCommere v2.1.x
  • Fixed table width problem for option settings page
Download this release

Release Info

Developer terrytsang
Plugin Icon 128x128 WooCommerce Direct Checkout
Version 1.0.5
Comparing to
See all releases

Code changes from version 1.0.7 to 1.0.5

Files changed (4) hide show
  1. .project +11 -0
  2. readme.txt +5 -13
  3. screenshot-1.png +0 -0
  4. wc-direct-checkout.php +316 -344
.project ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <projectDescription>
3
+ <name>woocommerce-direct-checkout</name>
4
+ <comment></comment>
5
+ <projects>
6
+ </projects>
7
+ <buildSpec>
8
+ </buildSpec>
9
+ <natures>
10
+ </natures>
11
+ </projectDescription>
readme.txt CHANGED
@@ -5,9 +5,9 @@ Plugin Name: WooCommerce Custom Direct Checkout
5
  Plugin URI: http://terrytsang.com/shop/shop/woocommerce-direct-checkout/
6
  Tags: woocommerce, custom fields, direct, checkout, e-commerce
7
  Requires at least: 2.7
8
- Tested up to: 3.9.1
9
- Stable tag: 1.0.7
10
- Version: 1.0.7
11
  License: GPLv2 or later
12
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
13
 
@@ -20,8 +20,8 @@ A WooCommerce plugin that aims to simplify the checkout process, leading to an i
20
  In WooCommerce Settings Panel, there will be a new submenu link called 'Direct Checkout' where you can:
21
 
22
  * Enabled / Disabled the direct checkout option
23
- * Change "Add to cart" to any text (Option to exclude external product)
24
- * Update "Redirect to Page" option
25
 
26
  = Features =
27
 
@@ -56,14 +56,6 @@ http://terrytsang.com/shop/shop/woocommerce-direct-checkout-pro/
56
 
57
  == Changelog ==
58
 
59
- = 1.0.7 =
60
-
61
- * Updated PRO version download link
62
-
63
- = 1.0.6 =
64
-
65
- * Added 'Exclude external product' checkbox for Custom Add to Cart Text option
66
-
67
  = 1.0.5 =
68
 
69
  * Updated "Add to cart" filter with WooCommere v2.1.x
5
  Plugin URI: http://terrytsang.com/shop/shop/woocommerce-direct-checkout/
6
  Tags: woocommerce, custom fields, direct, checkout, e-commerce
7
  Requires at least: 2.7
8
+ Tested up to: 3.8.1
9
+ Stable tag: 1.0.5
10
+ Version: 1.0.5
11
  License: GPLv2 or later
12
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
13
 
20
  In WooCommerce Settings Panel, there will be a new submenu link called 'Direct Checkout' where you can:
21
 
22
  * Enabled / Disabled the direct checkout option
23
+ * Change "Add to cart" to any text
24
+ * Update "Redirect to Page" option (NEW)
25
 
26
  = Features =
27
 
56
 
57
  == Changelog ==
58
 
 
 
 
 
 
 
 
 
59
  = 1.0.5 =
60
 
61
  * Updated "Add to cart" filter with WooCommere v2.1.x
screenshot-1.png CHANGED
Binary file
wc-direct-checkout.php CHANGED
@@ -1,346 +1,318 @@
1
- <?php
2
- /*
3
- Plugin Name: WooCommerce Direct Checkout
4
- Plugin URI: http://terrytsang.com/shop/shop/woocommerce-direct-checkout/
5
- Description: Allow you to implement direct checkout (skip cart page) for WooCommerce
6
- Version: 1.0.7
7
- Author: Terry Tsang
8
- Author URI: http://shop.terrytsang.com
9
- */
10
-
11
- /* Copyright 2012-2014 Terry Tsang (email: terrytsang811@gmail.com)
12
-
13
- This program is free software; you can redistribute it and/or modify
14
- it under the terms of the GNU General Public License as published by
15
- the Free Software Foundation; either version 2 of the License, or
16
- (at your option) any later version.
17
-
18
- This program is distributed in the hope that it will be useful,
19
- but WITHOUT ANY WARRANTY; without even the implied warranty of
20
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
- GNU General Public License for more details.
22
-
23
- You should have received a copy of the GNU General Public License
24
- along with this program; if not, write to the Free Software
25
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26
- */
27
-
28
- // Define plugin name
29
- define('wc_plugin_name_direct_checkout', 'WooCommerce Direct Checkout');
30
-
31
- // Define plugin version
32
- define('wc_version_direct_checkout', '1.0.7');
33
-
34
-
35
- // Checks if the WooCommerce plugins is installed and active.
36
- if(in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins')))){
37
- if(!class_exists('WooCommerce_Direct_Checkout')){
38
- class WooCommerce_Direct_Checkout{
39
-
40
- public static $plugin_prefix;
41
- public static $plugin_url;
42
- public static $plugin_path;
43
- public static $plugin_basefile;
44
-
45
- /**
46
- * Gets things started by adding an action to initialize this plugin once
47
- * WooCommerce is known to be active and initialized
48
- */
49
- public function __construct(){
50
- load_plugin_textdomain('wc-direct-checkout', false, dirname(plugin_basename(__FILE__)) . '/languages/');
51
-
52
- WooCommerce_Direct_Checkout::$plugin_prefix = 'wc_direct_checkout_';
53
- WooCommerce_Direct_Checkout::$plugin_basefile = plugin_basename(__FILE__);
54
- WooCommerce_Direct_Checkout::$plugin_url = plugin_dir_url(WooCommerce_Direct_Checkout::$plugin_basefile);
55
- WooCommerce_Direct_Checkout::$plugin_path = trailingslashit(dirname(__FILE__));
56
-
57
- $this->textdomain = 'wc-direct-checkout';
58
-
59
- $this->options_direct_checkout = array(
60
- 'direct_checkout_enabled' => '',
61
- 'direct_checkout_cart_button_text' => '',
62
- 'direct_checkout_exclude_external' => '',
63
- 'direct_checkout_cart_redirect_url' => ''
64
- );
65
-
66
- $this->saved_options_direct_checkout = array();
67
-
68
- add_action('woocommerce_init', array(&$this, 'init'));
69
- }
70
-
71
- /**
72
- * Initialize extension when WooCommerce is active
73
- */
74
- public function init(){
75
-
76
- //add menu link for the plugin (backend)
77
- add_action( 'admin_menu', array( &$this, 'add_menu_direct_checkout' ) );
78
-
79
- if(get_option('direct_checkout_enabled'))
80
- {
81
- //unset all related options to disabled / not active
82
- update_option('woocommerce_cart_redirect_after_add', 'no');
83
- update_option('woocommerce_enable_ajax_add_to_cart', 'no');
84
-
85
- add_filter('add_to_cart_redirect', array( &$this, 'custom_add_to_cart_redirect') );
86
- add_filter('single_add_to_cart_text', array( &$this, 'custom_cart_button_text') );
87
- add_filter('add_to_cart_text', array( &$this, 'custom_cart_button_text') );
88
-
89
  add_filter('woocommerce_product_single_add_to_cart_text', array( &$this, 'custom_cart_button_text') );
90
- add_filter('woocommerce_product_add_to_cart_text', array( &$this, 'custom_cart_button_text') );
91
- }
92
- }
93
-
94
- /**
95
- * Set custom add to cart redirect
96
- */
97
- function custom_add_to_cart_redirect() {
98
- $direct_checkout_cart_redirect_url = get_option( 'direct_checkout_cart_redirect_url' );
99
-
100
- if($direct_checkout_cart_redirect_url != "")
101
- return $direct_checkout_cart_redirect_url; // Replace with the url of your choosing
102
- else
103
- return get_permalink(get_option('woocommerce_checkout_page_id'));
104
- }
105
-
106
- /**
107
- * Set custom add to cart text
108
- */
109
- function custom_cart_button_text() {
110
- global $post;
111
-
112
-
113
-
114
- $direct_checkout_cart_button_text = get_option( 'direct_checkout_cart_button_text' ) ? get_option( 'direct_checkout_cart_button_text' ) : "Add to cart";
115
- $direct_checkout_exclude_external = get_option( 'direct_checkout_exclude_external' );
116
-
117
- if($direct_checkout_exclude_external){
118
-
119
- if( function_exists('get_product') ){
120
- $product = get_product( $post->ID );
121
-
122
- if( !$product->is_type( 'external' ) && $direct_checkout_cart_button_text && $direct_checkout_cart_button_text != ""){
123
- return __($direct_checkout_cart_button_text, $this->textdomain);
124
- } else {
125
- $button_text = get_post_meta( $post->ID, '_button_text', true ) ? get_post_meta( $post->ID, '_button_text', true ) : 'Buy product';
126
- return __($button_text, $this->textdomain);
127
- }
128
- }
129
-
130
- } else {
131
- if($direct_checkout_cart_button_text && $direct_checkout_cart_button_text != "")
132
- return __($direct_checkout_cart_button_text, $this->textdomain);
133
- }
134
-
135
- }
136
-
137
- /**
138
- * Add a menu link to the woocommerce section menu
139
- */
140
- function add_menu_direct_checkout() {
141
- $wc_page = 'woocommerce';
142
- $comparable_settings_page = add_submenu_page( $wc_page , __( 'Direct Checkout', $this->textdomain ), __( 'Direct Checkout', $this->textdomain ), 'manage_options', 'wc-direct-checkout', array(
143
- &$this,
144
- 'settings_page_direct_checkout'
145
- ));
146
- }
147
-
148
- /**
149
- * Create the settings page content
150
- */
151
- public function settings_page_direct_checkout() {
152
-
153
- // If form was submitted
154
- if ( isset( $_POST['submitted'] ) )
155
- {
156
- check_admin_referer( $this->textdomain );
157
-
158
- $this->saved_options_direct_checkout['direct_checkout_enabled'] = ! isset( $_POST['direct_checkout_enabled'] ) ? '1' : $_POST['direct_checkout_enabled'];
159
- $this->saved_options_direct_checkout['direct_checkout_cart_button_text'] = ! isset( $_POST['direct_checkout_cart_button_text'] ) ? 'Add to cart' : $_POST['direct_checkout_cart_button_text'];
160
- $this->saved_options_direct_checkout['direct_checkout_exclude_external'] = ! isset( $_POST['direct_checkout_exclude_external'] ) ? '1' : $_POST['direct_checkout_exclude_external'];
161
- $this->saved_options_direct_checkout['direct_checkout_cart_redirect_url'] = ! isset( $_POST['direct_checkout_cart_redirect_url'] ) ? '' : $_POST['direct_checkout_cart_redirect_url'];
162
-
163
- foreach($this->options_direct_checkout as $field => $value)
164
- {
165
- $option_direct_checkout = get_option( $field );
166
-
167
- if($option_direct_checkout != $this->saved_options_direct_checkout[$field])
168
- update_option( $field, $this->saved_options_direct_checkout[$field] );
169
- }
170
-
171
- // Show message
172
- echo '<div id="message" class="updated fade"><p>' . __( 'You have saved WooCommerce Direct Checkout options.', $this->textdomain ) . '</p></div>';
173
- }
174
-
175
- $direct_checkout_enabled = get_option( 'direct_checkout_enabled' );
176
- $direct_checkout_cart_button_text = get_option( 'direct_checkout_cart_button_text' ) ? get_option( 'direct_checkout_cart_button_text' ) : 'Add to Cart';
177
- $direct_checkout_exclude_external = get_option( 'direct_checkout_exclude_external' );
178
- $direct_checkout_cart_redirect_url = get_option( 'direct_checkout_cart_redirect_url' );
179
-
180
- $checked_enabled = '';
181
-
182
- if($direct_checkout_enabled)
183
- $checked_enabled = 'checked="checked"';
184
-
185
- if($direct_checkout_exclude_external)
186
- $checked_enabled_exclude = 'checked="checked"';
187
-
188
- $actionurl = $_SERVER['REQUEST_URI'];
189
- $nonce = wp_create_nonce( $this->textdomain );
190
-
191
-
192
- // Configuration Page
193
-
194
- ?>
195
- <div id="icon-options-general" class="icon32"></div>
196
- <h3><?php _e( 'Direct Checkout Options', $this->textdomain); ?></h3>
197
-
198
-
199
- <table style="width:90%;padding:5px;border-collapse:separate;border-spacing:5px;vertical-align:top;">
200
- <tr>
201
- <td colspan="2">Checking out is the most important and key part of placing an order online, and many users end up abandoning their order at the end. This plugin will simplify the checkout process, leading to an immediate increase in sales.</td>
202
- </tr>
203
- <tr>
204
- <td width="70%" style="vertical-align:top;">
205
- <form action="<?php echo $actionurl; ?>" method="post">
206
- <table>
207
- <tbody>
208
- <tr>
209
- <td colspan="2">
210
- <table class="widefat fixed" cellspacing="2" cellpadding="5" border="0">
211
- <tr>
212
- <td width="25%"><?php _e( 'Enable', $this->textdomain ); ?></td>
213
- <td>
214
- <input class="checkbox" name="direct_checkout_enabled" id="direct_checkout_enabled" value="0" type="hidden">
215
- <input class="checkbox" name="direct_checkout_enabled" id="direct_checkout_enabled" value="1" type="checkbox" <?php echo $checked_enabled; ?> type="checkbox">
216
- </td>
217
- </tr>
218
- <tr>
219
- <td width="25%"><?php _e( 'Custom Add to Cart Text', $this->textdomain ); ?></td>
220
- <td>
221
- <input name="direct_checkout_cart_button_text" id="direct_checkout_cart_button_text" value="<?php echo $direct_checkout_cart_button_text; ?>" />
222
- <input class="checkbox" name="direct_checkout_exclude_external" id="direct_checkout_exclude_external" value="0" type="hidden">
223
- <input class="checkbox" name="direct_checkout_exclude_external" id="direct_checkout_exclude_external" value="1" type="checkbox" <?php echo $checked_enabled_exclude; ?> type="checkbox">&nbsp;<i>Exclude External Product</i>
224
- </td>
225
- </tr>
226
- <tr>
227
- <td width="25%"><?php _e( 'Redirect to Page', $this->textdomain ); ?><br /><span style="color:#ccc;"><?php _e( '(Default will be checkout page if not set)', $this->textdomain ); ?></span></td>
228
- <td>
229
- <select name="direct_checkout_cart_redirect_url">
230
- <option value=""><?php echo esc_attr( __( 'Select page' ) ); ?></option>
231
- <?php
232
- $pages = get_pages();
233
- foreach ( $pages as $page ) {
234
- if($direct_checkout_cart_redirect_url == get_permalink( $page->ID ))
235
- $option = '<option value="' . get_permalink( $page->ID ) . '" selected="selected">';
236
- else
237
- $option = '<option value="' . get_permalink( $page->ID ) . '">';
238
- $option .= $page->post_title;
239
- $option .= '</option>';
240
- echo $option;
241
- }
242
- ?>
243
- </select>
244
- </td>
245
- </tr>
246
- </table>
247
- </td>
248
- </tr>
249
- <tr>
250
- <td colspan=2">
251
- <input class="button-primary" type="submit" name="Save" value="<?php _e('Save Options', $this->textdomain); ?>" id="submitbutton" />
252
- <input type="hidden" name="submitted" value="1" />
253
- <input type="hidden" id="_wpnonce" name="_wpnonce" value="<?php echo $nonce; ?>" />
254
- </td>
255
- </tr>
256
- </tbody>
257
- </table>
258
- </form>
259
-
260
- </td>
261
-
262
- <td width="30%" style="background:#ececec;padding:10px 5px;" valign="top">
263
- <div style="float:left;width:200px;">
264
- <a href="https://twitter.com/terrytsang811" class="twitter-follow-button" data-show-count="false" data-lang="en">Follow @terrytsang811</a>
265
- <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
266
- </div>
267
- <div>
268
- <div id="fb-root"></div>
269
- <script>(function(d, s, id) {
270
- var js, fjs = d.getElementsByTagName(s)[0];
271
- if (d.getElementById(id)) return;
272
- js = d.createElement(s); js.id = id;
273
- js.src = "//connect.facebook.net/en_GB/all.js#xfbml=1&appId=354404357988395";
274
- fjs.parentNode.insertBefore(js, fjs);
275
- }(document, 'script', 'facebook-jssdk'));</script>
276
- <div class="fb-like" data-href="http://wordpress.org/plugins/woocommerce-direct-checkout/" data-layout="button" data-action="like" data-show-faces="false" data-share="false"></div>
277
- </div>
278
- <p><b>WooCommerce Direct Checkout</b> is a FREE woocommerce plugin developed by <a href="http://shop.terrytsang.com" target="_blank" title="Terry Tsang - a PHP Developer and Wordpress Consultant">Terry Tsang</a>. This plugin aims to add direct checkout for WooCommerce.</p>
279
-
280
- <?php
281
- $get_pro_image = WooCommerce_Direct_Checkout::$plugin_url . '/images/direct-checkout-pro-version.png';
282
- ?>
283
- <div align="center"><a href="http://terrytsang.com/shop/shop/woocommerce-direct-checkout-pro/" target="_blank" title="WooCommerce Direct Checkout PRO"><img src="<?php echo $get_pro_image; ?>" border="0" /></a></div>
284
-
285
- <h3>Get More Plugins</h3>
286
-
287
- <p><a href="http://shop.terrytsang.com" target="_blank" title="Premium &amp; Free Extensions/Plugins for E-Commerce by Terry Tsang">Go to My Site</a> to get more free and premium extensions/plugins for your ecommerce sites.</p>
288
-
289
- <h3>Spreading the Word</h3>
290
-
291
- <ul style="list-style:dash">If you find this plugin helpful, you can:
292
- <li>- Write and review about it in your blog</li>
293
- <li>- Rate it on <a href="http://wordpress.org/extend/plugins/woocommerce-direct-checkout/" target="_blank">wordpress plugin page</a></li>
294
- <li>- Share on your social media<br />
295
- <a href="http://www.facebook.com/sharer.php?u=http://terrytsang.com/shop/shop/woocommerce-direct-checkout/&amp;t=WooCommerce Direct Checkout" title="Share this WooCommerce Direct Checkout on Facebook" target="_blank"><img src="http://terrytsang.com/shop/images/social_facebook.png" alt="Share this WooCommerce Direct Checkout plugin on Facebook"></a>
296
- <a href="https://twitter.com/intent/tweet?url=http%3A%2F%2Fterrytsang.com%2Fshop%2Fshop%2Fwoocommerce-direct-checkout%2F&text=WooCommerce Direct Checkout - &via=terrytsang811" target="_blank"><img src="http://terrytsang.com/shop/images/social_twitter.png" alt="Tweet about WooCommerce Direct Checkout plugin"></a>
297
- <a href="http://linkedin.com/shareArticle?mini=true&amp;url=http://terrytsang.com/shop/shop/woocommerce-direct-checkout/&amp;title=WooCommerce Direct Checkout plugin" title="Share this WooCommerce Direct Checkout plugin on LinkedIn" target="_blank"><img src="http://terrytsang.com/shop/images/social_linkedin.png" alt="Share this WooCommerce Direct Checkout plugin on LinkedIn"></a>
298
- </li>
299
- <li>- Or make a donation</li>
300
- </ul>
301
-
302
- <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=LJWSJDBBLNK7W" target="_blank"><img src="https://www.paypal.com/en_US/i/btn/btn_donate_LG.gif" border="0" alt="" /></a>
303
-
304
- <h3>Thank you for your support!</h3>
305
- </td>
306
-
307
- </tr>
308
- </table>
309
-
310
-
311
- <br />
312
-
313
- <?php
314
- }
315
-
316
- /**
317
- * Get the setting options
318
- */
319
- function get_options() {
320
-
321
- foreach($this->options_direct_checkout as $field => $value)
322
- {
323
- $array_options[$field] = get_option( $field );
324
- }
325
-
326
- return $array_options;
327
- }
328
-
329
-
330
- }//end class
331
-
332
- }//if class does not exist
333
-
334
- $woocommerce_direct_checkout = new WooCommerce_Direct_Checkout();
335
- }
336
- else{
337
- add_action('admin_notices', 'wc_direct_checkout_error_notice');
338
- function wc_direct_checkout_error_notice(){
339
- global $current_screen;
340
- if($current_screen->parent_base == 'plugins'){
341
- echo '<div class="error"><p>'.__(wc_plugin_name_direct_checkout.' requires <a href="http://www.woothemes.com/woocommerce/" target="_blank">WooCommerce</a> to be activated in order to work. Please install and activate <a href="'.admin_url('plugin-install.php?tab=search&type=term&s=WooCommerce').'" target="_blank">WooCommerce</a> first.').'</p></div>';
342
- }
343
- }
344
- }
345
-
346
  ?>
1
+ <?php
2
+ /*
3
+ Plugin Name: WooCommerce Direct Checkout
4
+ Plugin URI: http://terrytsang.com/shop/shop/woocommerce-direct-checkout/
5
+ Description: Allow you to implement direct checkout (skip cart page) for WooCommerce
6
+ Version: 1.0.5
7
+ Author: Terry Tsang
8
+ Author URI: http://shop.terrytsang.com
9
+ */
10
+
11
+ /* Copyright 2012-2014 Terry Tsang (email: terrytsang811@gmail.com)
12
+
13
+ This program is free software; you can redistribute it and/or modify
14
+ it under the terms of the GNU General Public License as published by
15
+ the Free Software Foundation; either version 2 of the License, or
16
+ (at your option) any later version.
17
+
18
+ This program is distributed in the hope that it will be useful,
19
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
20
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
+ GNU General Public License for more details.
22
+
23
+ You should have received a copy of the GNU General Public License
24
+ along with this program; if not, write to the Free Software
25
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26
+ */
27
+
28
+ // Define plugin name
29
+ define('wc_plugin_name_direct_checkout', 'WooCommerce Direct Checkout');
30
+
31
+ // Define plugin version
32
+ define('wc_version_direct_checkout', '1.0.5');
33
+
34
+
35
+ // Checks if the WooCommerce plugins is installed and active.
36
+ if(in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins')))){
37
+ if(!class_exists('WooCommerce_Direct_Checkout')){
38
+ class WooCommerce_Direct_Checkout{
39
+
40
+ public static $plugin_prefix;
41
+ public static $plugin_url;
42
+ public static $plugin_path;
43
+ public static $plugin_basefile;
44
+
45
+ /**
46
+ * Gets things started by adding an action to initialize this plugin once
47
+ * WooCommerce is known to be active and initialized
48
+ */
49
+ public function __construct(){
50
+ load_plugin_textdomain('wc-direct-checkout', false, dirname(plugin_basename(__FILE__)) . '/languages/');
51
+
52
+ WooCommerce_Direct_Checkout::$plugin_prefix = 'wc_direct_checkout_';
53
+ WooCommerce_Direct_Checkout::$plugin_basefile = plugin_basename(__FILE__);
54
+ WooCommerce_Direct_Checkout::$plugin_url = plugin_dir_url(WooCommerce_Direct_Checkout::$plugin_basefile);
55
+ WooCommerce_Direct_Checkout::$plugin_path = trailingslashit(dirname(__FILE__));
56
+
57
+ $this->textdomain = 'wc-direct-checkout';
58
+
59
+ $this->options_direct_checkout = array(
60
+ 'direct_checkout_enabled' => '',
61
+ 'direct_checkout_cart_button_text' => '',
62
+ 'direct_checkout_cart_redirect_url' => ''
63
+ );
64
+
65
+ $this->saved_options_direct_checkout = array();
66
+
67
+ add_action('woocommerce_init', array(&$this, 'init'));
68
+ }
69
+
70
+ /**
71
+ * Initialize extension when WooCommerce is active
72
+ */
73
+ public function init(){
74
+
75
+ //add menu link for the plugin (backend)
76
+ add_action( 'admin_menu', array( &$this, 'add_menu_direct_checkout' ) );
77
+
78
+ if(get_option('direct_checkout_enabled'))
79
+ {
80
+ //unset all related options to disabled / not active
81
+ update_option('woocommerce_cart_redirect_after_add', 'no');
82
+ update_option('woocommerce_enable_ajax_add_to_cart', 'no');
83
+
84
+ add_filter('add_to_cart_redirect', array( &$this, 'custom_add_to_cart_redirect') );
85
+ add_filter('single_add_to_cart_text', array( &$this, 'custom_cart_button_text') );
86
+ add_filter('add_to_cart_text', array( &$this, 'custom_cart_button_text') );
87
+
 
88
  add_filter('woocommerce_product_single_add_to_cart_text', array( &$this, 'custom_cart_button_text') );
89
+ add_filter('woocommerce_product_add_to_cart_text', array( &$this, 'custom_cart_button_text') );
90
+ }
91
+ }
92
+
93
+ /**
94
+ * Set custom add to cart redirect
95
+ */
96
+ function custom_add_to_cart_redirect() {
97
+ $direct_checkout_cart_redirect_url = get_option( 'direct_checkout_cart_redirect_url' );
98
+
99
+ if($direct_checkout_cart_redirect_url != "")
100
+ return $direct_checkout_cart_redirect_url; // Replace with the url of your choosing
101
+ else
102
+ return get_permalink(get_option('woocommerce_checkout_page_id'));
103
+ }
104
+
105
+ /**
106
+ * Set custom add to cart text
107
+ */
108
+ function custom_cart_button_text() {
109
+ $direct_checkout_cart_button_text = get_option( 'direct_checkout_cart_button_text' ) ? get_option( 'direct_checkout_cart_button_text' ) : "Add to cart";
110
+
111
+ if($direct_checkout_cart_button_text && $direct_checkout_cart_button_text != "")
112
+ return __($direct_checkout_cart_button_text, $this->textdomain);
113
+
114
+ }
115
+
116
+ /**
117
+ * Add a menu link to the woocommerce section menu
118
+ */
119
+ function add_menu_direct_checkout() {
120
+ $wc_page = 'woocommerce';
121
+ $comparable_settings_page = add_submenu_page( $wc_page , __( 'Direct Checkout', $this->textdomain ), __( 'Direct Checkout', $this->textdomain ), 'manage_options', 'wc-direct-checkout', array(
122
+ &$this,
123
+ 'settings_page_direct_checkout'
124
+ ));
125
+ }
126
+
127
+ /**
128
+ * Create the settings page content
129
+ */
130
+ public function settings_page_direct_checkout() {
131
+
132
+ // If form was submitted
133
+ if ( isset( $_POST['submitted'] ) )
134
+ {
135
+ check_admin_referer( $this->textdomain );
136
+
137
+ $this->saved_options_direct_checkout['direct_checkout_enabled'] = ! isset( $_POST['direct_checkout_enabled'] ) ? '1' : $_POST['direct_checkout_enabled'];
138
+ $this->saved_options_direct_checkout['direct_checkout_cart_button_text'] = ! isset( $_POST['direct_checkout_cart_button_text'] ) ? 'Add to cart' : $_POST['direct_checkout_cart_button_text'];
139
+ $this->saved_options_direct_checkout['direct_checkout_cart_redirect_url'] = ! isset( $_POST['direct_checkout_cart_redirect_url'] ) ? '' : $_POST['direct_checkout_cart_redirect_url'];
140
+
141
+ foreach($this->options_direct_checkout as $field => $value)
142
+ {
143
+ $option_direct_checkout = get_option( $field );
144
+
145
+ if($option_direct_checkout != $this->saved_options_direct_checkout[$field])
146
+ update_option( $field, $this->saved_options_direct_checkout[$field] );
147
+ }
148
+
149
+ // Show message
150
+ echo '<div id="message" class="updated fade"><p>' . __( 'You have saved WooCommerce Direct Checkout options.', $this->textdomain ) . '</p></div>';
151
+ }
152
+
153
+ $direct_checkout_enabled = get_option( 'direct_checkout_enabled' );
154
+ $direct_checkout_cart_button_text = get_option( 'direct_checkout_cart_button_text' ) ? get_option( 'direct_checkout_cart_button_text' ) : 'Add to Cart';
155
+ $direct_checkout_cart_redirect_url = get_option( 'direct_checkout_cart_redirect_url' );
156
+
157
+ $checked_enabled = '';
158
+
159
+ if($direct_checkout_enabled)
160
+ $checked_enabled = 'checked="checked"';
161
+
162
+ $actionurl = $_SERVER['REQUEST_URI'];
163
+ $nonce = wp_create_nonce( $this->textdomain );
164
+
165
+
166
+ // Configuration Page
167
+
168
+ ?>
169
+ <div id="icon-options-general" class="icon32"></div>
170
+ <h3><?php _e( 'Direct Checkout Options', $this->textdomain); ?></h3>
171
+
172
+
173
+ <table style="width:90%;padding:5px;border-collapse:separate;border-spacing:5px;vertical-align:top;">
174
+ <tr>
175
+ <td colspan="2">Checking out is the most important and key part of placing an order online, and many users end up abandoning their order at the end. This plugin will simplify the checkout process, leading to an immediate increase in sales.</td>
176
+ </tr>
177
+ <tr>
178
+ <td width="70%" style="vertical-align:top;">
179
+ <form action="<?php echo $actionurl; ?>" method="post">
180
+ <table>
181
+ <tbody>
182
+ <tr>
183
+ <td colspan="2">
184
+ <table class="widefat fixed" cellspacing="2" cellpadding="5" border="0">
185
+ <tr>
186
+ <td width="25%"><?php _e( 'Enable', $this->textdomain ); ?></td>
187
+ <td>
188
+ <input class="checkbox" name="direct_checkout_enabled" id="direct_checkout_enabled" value="0" type="hidden">
189
+ <input class="checkbox" name="direct_checkout_enabled" id="direct_checkout_enabled" value="1" type="checkbox" <?php echo $checked_enabled; ?> type="checkbox">
190
+ </td>
191
+ </tr>
192
+ <tr>
193
+ <td width="25%"><?php _e( 'Custom Add to Cart Text', $this->textdomain ); ?></td>
194
+ <td>
195
+ <input name="direct_checkout_cart_button_text" id="direct_checkout_cart_button_text" value="<?php echo $direct_checkout_cart_button_text; ?>" />
196
+ </td>
197
+ </tr>
198
+ <tr>
199
+ <td width="25%"><?php _e( 'Redirect to Page', $this->textdomain ); ?><br /><span style="color:#ccc;"><?php _e( '(Default will be checkout page if not set)', $this->textdomain ); ?></span></td>
200
+ <td>
201
+ <select name="direct_checkout_cart_redirect_url">
202
+ <option value=""><?php echo esc_attr( __( 'Select page' ) ); ?></option>
203
+ <?php
204
+ $pages = get_pages();
205
+ foreach ( $pages as $page ) {
206
+ if($direct_checkout_cart_redirect_url == get_permalink( $page->ID ))
207
+ $option = '<option value="' . get_permalink( $page->ID ) . '" selected="selected">';
208
+ else
209
+ $option = '<option value="' . get_permalink( $page->ID ) . '">';
210
+ $option .= $page->post_title;
211
+ $option .= '</option>';
212
+ echo $option;
213
+ }
214
+ ?>
215
+ </select>
216
+ </td>
217
+ </tr>
218
+ </table>
219
+ </td>
220
+ </tr>
221
+ <tr>
222
+ <td colspan=2">
223
+ <input class="button-primary" type="submit" name="Save" value="<?php _e('Save Options', $this->textdomain); ?>" id="submitbutton" />
224
+ <input type="hidden" name="submitted" value="1" />
225
+ <input type="hidden" id="_wpnonce" name="_wpnonce" value="<?php echo $nonce; ?>" />
226
+ </td>
227
+ </tr>
228
+ </tbody>
229
+ </table>
230
+ </form>
231
+
232
+ </td>
233
+
234
+ <td width="30%" style="background:#ececec;padding:10px 5px;" valign="top">
235
+ <div style="float:left;width:200px;">
236
+ <a href="https://twitter.com/terrytsang811" class="twitter-follow-button" data-show-count="false" data-lang="en">Follow @terrytsang811</a>
237
+ <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
238
+ </div>
239
+ <div>
240
+ <div id="fb-root"></div>
241
+ <script>(function(d, s, id) {
242
+ var js, fjs = d.getElementsByTagName(s)[0];
243
+ if (d.getElementById(id)) return;
244
+ js = d.createElement(s); js.id = id;
245
+ js.src = "//connect.facebook.net/en_GB/all.js#xfbml=1&appId=354404357988395";
246
+ fjs.parentNode.insertBefore(js, fjs);
247
+ }(document, 'script', 'facebook-jssdk'));</script>
248
+ <div class="fb-like" data-href="http://wordpress.org/plugins/woocommerce-direct-checkout/" data-layout="button" data-action="like" data-show-faces="false" data-share="false"></div>
249
+ </div>
250
+ <p><b>WooCommerce Direct Checkout</b> is a FREE woocommerce plugin developed by <a href="http://shop.terrytsang.com" target="_blank" title="Terry Tsang - a PHP Developer and Wordpress Consultant">Terry Tsang</a>. This plugin aims to add direct checkout for WooCommerce.</p>
251
+
252
+ <?php
253
+ $get_pro_image = WooCommerce_Direct_Checkout::$plugin_url . '/images/direct-checkout-pro-version.png';
254
+ ?>
255
+ <div align="center"><a href="http://terrytsang.com/shop/shop/woocommerce-direct-checkout-pro/" target="_blank" title="WooCommerce Direct Checkout PRO"><img src="<?php echo $get_pro_image; ?>" border="0" /></a></div>
256
+
257
+ <h3>Get More Plugins</h3>
258
+
259
+ <p><a href="http://shop.terrytsang.com" target="_blank" title="Premium &amp; Free Extensions/Plugins for E-Commerce by Terry Tsang">Go to My Site</a> to get more free and premium extensions/plugins for your ecommerce sites.</p>
260
+
261
+ <h3>Spreading the Word</h3>
262
+
263
+ <ul style="list-style:dash">If you find this plugin helpful, you can:
264
+ <li>- Write and review about it in your blog</li>
265
+ <li>- Rate it on <a href="http://wordpress.org/extend/plugins/woocommerce-direct-checkout/" target="_blank">wordpress plugin page</a></li>
266
+ <li>- Share on your social media<br />
267
+ <a href="http://www.facebook.com/sharer.php?u=http://terrytsang.com/shop/shop/woocommerce-direct-checkout/&amp;t=WooCommerce Direct Checkout" title="Share this WooCommerce Direct Checkout on Facebook" target="_blank"><img src="http://terrytsang.com/shop/images/social_facebook.png" alt="Share this WooCommerce Direct Checkout plugin on Facebook"></a>
268
+ <a href="https://twitter.com/intent/tweet?url=http%3A%2F%2Fterrytsang.com%2Fshop%2Fshop%2Fwoocommerce-direct-checkout%2F&text=WooCommerce Direct Checkout - &via=terrytsang811" target="_blank"><img src="http://terrytsang.com/shop/images/social_twitter.png" alt="Tweet about WooCommerce Direct Checkout plugin"></a>
269
+ <a href="http://linkedin.com/shareArticle?mini=true&amp;url=http://terrytsang.com/shop/shop/woocommerce-direct-checkout/&amp;title=WooCommerce Direct Checkout plugin" title="Share this WooCommerce Direct Checkout plugin on LinkedIn" target="_blank"><img src="http://terrytsang.com/shop/images/social_linkedin.png" alt="Share this WooCommerce Direct Checkout plugin on LinkedIn"></a>
270
+ </li>
271
+ <li>- Or make a donation</li>
272
+ </ul>
273
+
274
+ <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=LJWSJDBBLNK7W" target="_blank"><img src="https://www.paypal.com/en_US/i/btn/btn_donate_LG.gif" border="0" alt="" /></a>
275
+
276
+ <h3>Thank you for your support!</h3>
277
+ </td>
278
+
279
+ </tr>
280
+ </table>
281
+
282
+
283
+ <br />
284
+
285
+ <?php
286
+ }
287
+
288
+ /**
289
+ * Get the setting options
290
+ */
291
+ function get_options() {
292
+
293
+ foreach($this->options_direct_checkout as $field => $value)
294
+ {
295
+ $array_options[$field] = get_option( $field );
296
+ }
297
+
298
+ return $array_options;
299
+ }
300
+
301
+
302
+ }//end class
303
+
304
+ }//if class does not exist
305
+
306
+ $woocommerce_direct_checkout = new WooCommerce_Direct_Checkout();
307
+ }
308
+ else{
309
+ add_action('admin_notices', 'wc_direct_checkout_error_notice');
310
+ function wc_direct_checkout_error_notice(){
311
+ global $current_screen;
312
+ if($current_screen->parent_base == 'plugins'){
313
+ echo '<div class="error"><p>'.__(wc_plugin_name_direct_checkout.' requires <a href="http://www.woothemes.com/woocommerce/" target="_blank">WooCommerce</a> to be activated in order to work. Please install and activate <a href="'.admin_url('plugin-install.php?tab=search&type=term&s=WooCommerce').'" target="_blank">WooCommerce</a> first.').'</p></div>';
314
+ }
315
+ }
316
+ }
317
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
318
  ?>