forked from woocommerce/woocommerce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
woocommerce.php
891 lines (766 loc) · 24.3 KB
/
woocommerce.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
<?php
/**
* Plugin Name: WooCommerce
* Plugin URI: http://www.woothemes.com/woocommerce/
* Description: An e-commerce toolkit that helps you sell anything. Beautifully.
* Version: 2.2.0-bleeding
* Author: WooThemes
* Author URI: http://woothemes.com
* Requires at least: 3.8
* Tested up to: 3.8
*
* Text Domain: woocommerce
* Domain Path: /i18n/languages/
*
* @package WooCommerce
* @category Core
* @author WooThemes
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! class_exists( 'WooCommerce' ) ) :
/**
* Main WooCommerce Class
*
* @class WooCommerce
* @version 2.1.0
*/
final class WooCommerce {
/**
* @var string
*/
public $version = '2.2.0';
/**
* @var WooCommerce The single instance of the class
* @since 2.1
*/
protected static $_instance = null;
/**
* @var WC_Session session
*/
public $session = null;
/**
* @var WC_Query $query
*/
public $query = null;
/**
* @var WC_Product_Factory $product_factory
*/
public $product_factory = null;
/**
* @var WC_Countries $countries
*/
public $countries = null;
/**
* @var WC_Integrations $integrations
*/
public $integrations = null;
/**
* @var WC_Cart $cart
*/
public $cart = null;
/**
* @var WC_Customer $customer
*/
public $customer = null;
/**
* Main WooCommerce Instance
*
* Ensures only one instance of WooCommerce is loaded or can be loaded.
*
* @since 2.1
* @static
* @see WC()
* @return WooCommerce - Main instance
*/
public static function instance() {
if ( is_null( self::$_instance ) ) {
self::$_instance = new self();
}
return self::$_instance;
}
/**
* Cloning is forbidden.
*
* @since 2.1
*/
public function __clone() {
_doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?' ), '2.1' );
}
/**
* Unserializing instances of this class is forbidden.
*
* @since 2.1
*/
public function __wakeup() {
_doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?' ), '2.1' );
}
/**
* WooCommerce Constructor.
* @access public
* @return WooCommerce
*/
public function __construct() {
// Auto-load classes on demand
if ( function_exists( "__autoload" ) ) {
spl_autoload_register( "__autoload" );
}
spl_autoload_register( array( $this, 'autoload' ) );
// Define constants
$this->define_constants();
// Include required files
$this->includes();
// Init API
$this->api = new WC_API();
// Hooks
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'action_links' ) );
add_action( 'widgets_init', array( $this, 'include_widgets' ) );
add_action( 'init', array( $this, 'init' ), 0 );
add_action( 'init', array( $this, 'include_template_functions' ) );
add_action( 'init', array( 'WC_Shortcodes', 'init' ) );
add_action( 'after_setup_theme', array( $this, 'setup_environment' ) );
// Loaded action
do_action( 'woocommerce_loaded' );
}
/**
* Auto-load in-accessible properties on demand.
*
* @param mixed $key
* @return mixed
*/
public function __get( $key ) {
if ( method_exists( $this, $key ) ) {
return $this->$key();
}
else switch( $key ) {
case 'template_url':
_deprecated_argument( 'Woocommerce->template_url', '2.1', 'WC_TEMPLATE_PATH constant' );
return WC_TEMPLATE_PATH;
case 'messages':
_deprecated_argument( 'Woocommerce->messages', '2.1', 'Use wc_get_notices' );
return wc_get_notices( 'success' );
case 'errors':
_deprecated_argument( 'Woocommerce->errors', '2.1', 'Use wc_get_notices' );
return wc_get_notices( 'error' );
default:
return false;
}
}
/**
* Show action links on the plugin screen
*
* @param mixed $links
* @return array
*/
public function action_links( $links ) {
return array_merge( array(
'<a href="' . admin_url( 'admin.php?page=wc-settings' ) . '">' . __( 'Settings', 'woocommerce' ) . '</a>',
'<a href="' . esc_url( apply_filters( 'woocommerce_docs_url', 'http://docs.woothemes.com/documentation/plugins/woocommerce/', 'woocommerce' ) ) . '">' . __( 'Docs', 'woocommerce' ) . '</a>',
'<a href="' . esc_url( apply_filters( 'woocommerce_support_url', 'http://support.woothemes.com/' ) ) . '">' . __( 'Premium Support', 'woocommerce' ) . '</a>',
), $links );
}
/**
* Auto-load WC classes on demand to reduce memory consumption.
*
* @param mixed $class
* @return void
*/
public function autoload( $class ) {
$class = strtolower( $class );
if ( strpos( $class, 'wc_gateway_' ) === 0 ) {
$path = $this->plugin_path() . '/includes/gateways/' . trailingslashit( substr( str_replace( '_', '-', $class ), 11 ) );
$file = 'class-' . str_replace( '_', '-', $class ) . '.php';
if ( is_readable( $path . $file ) ) {
include_once( $path . $file );
return;
}
} elseif ( strpos( $class, 'wc_shipping_' ) === 0 ) {
$path = $this->plugin_path() . '/includes/shipping/' . trailingslashit( substr( str_replace( '_', '-', $class ), 12 ) );
$file = 'class-' . str_replace( '_', '-', $class ) . '.php';
if ( is_readable( $path . $file ) ) {
include_once( $path . $file );
return;
}
} elseif ( strpos( $class, 'wc_shortcode_' ) === 0 ) {
$path = $this->plugin_path() . '/includes/shortcodes/';
$file = 'class-' . str_replace( '_', '-', $class ) . '.php';
if ( is_readable( $path . $file ) ) {
include_once( $path . $file );
return;
}
} elseif ( strpos( $class, 'wc_meta_box' ) === 0 ) {
$path = $this->plugin_path() . '/includes/admin/post-types/meta-boxes/';
$file = 'class-' . str_replace( '_', '-', $class ) . '.php';
if ( is_readable( $path . $file ) ) {
include_once( $path . $file );
return;
}
}
if ( strpos( $class, 'wc_' ) === 0 ) {
$path = $this->plugin_path() . '/includes/';
$file = 'class-' . str_replace( '_', '-', $class ) . '.php';
if ( is_readable( $path . $file ) ) {
include_once( $path . $file );
return;
}
}
}
/**
* Define WC Constants
*/
private function define_constants() {
define( 'WC_PLUGIN_FILE', __FILE__ );
define( 'WC_VERSION', $this->version );
define( 'WOOCOMMERCE_VERSION', WC_VERSION ); // Backwards compat
if ( ! defined( 'WC_TEMPLATE_PATH' ) ) {
define( 'WC_TEMPLATE_PATH', $this->template_path() );
}
if ( ! defined( 'WC_ROUNDING_PRECISION' ) ) {
define( 'WC_ROUNDING_PRECISION', 4 );
}
// 1 = PHP_ROUND_HALF_UP, 2 = PHP_ROUND_HALF_DOWN
if ( ! defined( 'WC_TAX_ROUNDING_MODE' ) ) {
define( 'WC_TAX_ROUNDING_MODE', get_option( 'woocommerce_prices_include_tax' ) === 'yes' ? 2 : 1 );
}
if ( ! defined( 'WC_DELIMITER' ) ) {
define( 'WC_DELIMITER', '|' );
}
}
/**
* Include required core files used in admin and on the frontend.
*/
private function includes() {
include( 'includes/wc-core-functions.php' );
include( 'includes/class-wc-install.php' );
include( 'includes/class-wc-download-handler.php' );
include( 'includes/class-wc-comments.php' );
include( 'includes/class-wc-post-data.php' );
if ( is_admin() ) {
include_once( 'includes/admin/class-wc-admin.php' );
}
if ( defined( 'DOING_AJAX' ) ) {
$this->ajax_includes();
}
if ( ! is_admin() || defined( 'DOING_AJAX' ) ) {
$this->frontend_includes();
}
// Query class
$this->query = include( 'includes/class-wc-query.php' ); // The main query class
// Post types
include_once( 'includes/class-wc-post-types.php' ); // Registers post types
// API Class
include_once( 'includes/class-wc-api.php' );
// Include abstract classes
include_once( 'includes/abstracts/abstract-wc-product.php' ); // Products
include_once( 'includes/abstracts/abstract-wc-settings-api.php' ); // Settings API (for gateways, shipping, and integrations)
include_once( 'includes/abstracts/abstract-wc-shipping-method.php' ); // A Shipping method
include_once( 'includes/abstracts/abstract-wc-payment-gateway.php' ); // A Payment gateway
include_once( 'includes/abstracts/abstract-wc-integration.php' ); // An integration with a service
// Classes (used on all pages)
include_once( 'includes/class-wc-product-factory.php' ); // Product factory
include_once( 'includes/class-wc-countries.php' ); // Defines countries and states
include_once( 'includes/class-wc-integrations.php' ); // Loads integrations
include_once( 'includes/class-wc-cache-helper.php' ); // Cache Helper
include_once( 'includes/class-wc-https.php' ); // https Helper
// Include template hooks in time for themes to remove/modify them
include_once( 'includes/wc-template-hooks.php' );
}
/**
* Include required ajax files.
*/
public function ajax_includes() {
include_once( 'includes/class-wc-ajax.php' ); // Ajax functions for admin and the front-end
}
/**
* Include required frontend files.
*/
public function frontend_includes() {
include_once( 'includes/class-wc-template-loader.php' ); // Template Loader
include_once( 'includes/class-wc-frontend-scripts.php' ); // Frontend Scripts
include_once( 'includes/class-wc-form-handler.php' ); // Form Handlers
include_once( 'includes/class-wc-cart.php' ); // The main cart class
include_once( 'includes/class-wc-tax.php' ); // Tax class
include_once( 'includes/class-wc-customer.php' ); // Customer class
include_once( 'includes/abstracts/abstract-wc-session.php' ); // Abstract for session implementations
include_once( 'includes/class-wc-session-handler.php' ); // WC Session class
include_once( 'includes/class-wc-shortcodes.php' ); // Shortcodes class
}
/**
* Function used to Init WooCommerce Template Functions - This makes them pluggable by plugins and themes.
*/
public function include_template_functions() {
include_once( 'includes/wc-template-functions.php' );
}
/**
* Include core widgets
*/
public function include_widgets() {
include_once( 'includes/abstracts/abstract-wc-widget.php' );
include_once( 'includes/widgets/class-wc-widget-cart.php' );
include_once( 'includes/widgets/class-wc-widget-products.php' );
include_once( 'includes/widgets/class-wc-widget-layered-nav.php' );
include_once( 'includes/widgets/class-wc-widget-layered-nav-filters.php' );
include_once( 'includes/widgets/class-wc-widget-price-filter.php' );
include_once( 'includes/widgets/class-wc-widget-product-categories.php' );
include_once( 'includes/widgets/class-wc-widget-product-search.php' );
include_once( 'includes/widgets/class-wc-widget-product-tag-cloud.php' );
include_once( 'includes/widgets/class-wc-widget-recent-reviews.php' );
include_once( 'includes/widgets/class-wc-widget-recently-viewed.php' );
include_once( 'includes/widgets/class-wc-widget-top-rated-products.php' );
}
/**
* Init WooCommerce when WordPress Initialises.
*/
public function init() {
// Before init action
do_action( 'before_woocommerce_init' );
// Set up localisation
$this->load_plugin_textdomain();
// Load class instances
$this->product_factory = new WC_Product_Factory(); // Product Factory to create new product instances
$this->countries = new WC_Countries(); // Countries class
$this->integrations = new WC_Integrations(); // Integrations class
// Classes/actions loaded for the frontend and for ajax requests
if ( ! is_admin() || defined( 'DOING_AJAX' ) ) {
// Session class, handles session data for customers - can be overwritten if custom handler is needed
$session_class = apply_filters( 'woocommerce_session_handler', 'WC_Session_Handler' );
// Class instances
$this->session = new $session_class();
$this->cart = new WC_Cart(); // Cart class, stores the cart contents
$this->customer = new WC_Customer(); // Customer class, handles data such as customer location
}
// Email Actions
$email_actions = array(
'woocommerce_low_stock',
'woocommerce_no_stock',
'woocommerce_product_on_backorder',
'woocommerce_order_status_pending_to_processing',
'woocommerce_order_status_pending_to_completed',
'woocommerce_order_status_pending_to_on-hold',
'woocommerce_order_status_failed_to_processing',
'woocommerce_order_status_failed_to_completed',
'woocommerce_order_status_completed',
'woocommerce_new_customer_note',
'woocommerce_created_customer'
);
foreach ( $email_actions as $action )
add_action( $action, array( $this, 'send_transactional_email' ), 10, 10 );
// Init action
do_action( 'woocommerce_init' );
}
/**
* Load Localisation files.
*
* Note: the first-loaded translation file overrides any following ones if the same translation is present
*/
public function load_plugin_textdomain() {
$locale = apply_filters( 'plugin_locale', get_locale(), 'woocommerce' );
// Admin Locale
if ( is_admin() ) {
load_textdomain( 'woocommerce', WP_LANG_DIR . "/woocommerce/woocommerce-admin-$locale.mo" );
load_textdomain( 'woocommerce', dirname( __FILE__ ) . "/i18n/languages/woocommerce-admin-$locale.mo" );
}
// Frontend Locale
load_textdomain( 'woocommerce', WP_LANG_DIR . "/woocommerce/woocommerce-$locale.mo" );
if ( apply_filters( 'woocommerce_load_alt_locale', false ) )
load_plugin_textdomain( 'woocommerce', false, plugin_basename( dirname( __FILE__ ) ) . "/i18n/languages/alt" );
else
load_plugin_textdomain( 'woocommerce', false, plugin_basename( dirname( __FILE__ ) ) . "/i18n/languages" );
}
/**
* Ensure theme and server variable compatibility and setup image sizes..
*/
public function setup_environment() {
// Post thumbnail support
if ( ! current_theme_supports( 'post-thumbnails', 'product' ) ) {
add_theme_support( 'post-thumbnails' );
remove_post_type_support( 'post', 'thumbnail' );
remove_post_type_support( 'page', 'thumbnail' );
} else {
add_post_type_support( 'product', 'thumbnail' );
}
// Add image sizes
$shop_thumbnail = wc_get_image_size( 'shop_thumbnail' );
$shop_catalog = wc_get_image_size( 'shop_catalog' );
$shop_single = wc_get_image_size( 'shop_single' );
add_image_size( 'shop_thumbnail', $shop_thumbnail['width'], $shop_thumbnail['height'], $shop_thumbnail['crop'] );
add_image_size( 'shop_catalog', $shop_catalog['width'], $shop_catalog['height'], $shop_catalog['crop'] );
add_image_size( 'shop_single', $shop_single['width'], $shop_single['height'], $shop_single['crop'] );
// IIS
if ( ! isset($_SERVER['REQUEST_URI'] ) ) {
$_SERVER['REQUEST_URI'] = substr( $_SERVER['PHP_SELF'], 1 );
if ( isset( $_SERVER['QUERY_STRING'] ) ) {
$_SERVER['REQUEST_URI'].='?'.$_SERVER['QUERY_STRING'];
}
}
// NGINX Proxy
if ( ! isset( $_SERVER['REMOTE_ADDR'] ) && isset( $_SERVER['HTTP_REMOTE_ADDR'] ) ) {
$_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_REMOTE_ADDR'];
}
if ( ! isset( $_SERVER['HTTPS'] ) && ! empty( $_SERVER['HTTP_HTTPS'] ) ) {
$_SERVER['HTTPS'] = $_SERVER['HTTP_HTTPS'];
}
// Support for hosts which don't use HTTPS, and use HTTP_X_FORWARDED_PROTO
if ( ! isset( $_SERVER['HTTPS'] ) && ! empty( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' ) {
$_SERVER['HTTPS'] = '1';
}
}
/** Helper functions ******************************************************/
/**
* Get the plugin url.
*
* @return string
*/
public function plugin_url() {
return untrailingslashit( plugins_url( '/', __FILE__ ) );
}
/**
* Get the plugin path.
*
* @return string
*/
public function plugin_path() {
return untrailingslashit( plugin_dir_path( __FILE__ ) );
}
/**
* Get the template path.
*
* @return string
*/
public function template_path() {
return apply_filters( 'WC_TEMPLATE_PATH', 'woocommerce/' );
}
/**
* Get Ajax URL.
*
* @return string
*/
public function ajax_url() {
return admin_url( 'admin-ajax.php', 'relative' );
}
/**
* Return the WC API URL for a given request
*
* @param mixed $request
* @param mixed $ssl (default: null)
* @return string
*/
public function api_request_url( $request, $ssl = null ) {
if ( is_null( $ssl ) ) {
$scheme = parse_url( get_option( 'home' ), PHP_URL_SCHEME );
} elseif ( $ssl ) {
$scheme = 'https';
} else {
$scheme = 'http';
}
if ( get_option('permalink_structure') ) {
return esc_url_raw( trailingslashit( home_url( '/wc-api/' . $request, $scheme ) ) );
} else {
return esc_url_raw( add_query_arg( 'wc-api', $request, trailingslashit( home_url( '', $scheme ) ) ) );
}
}
/**
* Init the mailer and call the notifications for the current filter.
* @internal param array $args (default: array())
* @return void
*/
public function send_transactional_email() {
$this->mailer();
$args = func_get_args();
do_action_ref_array( current_filter() . '_notification', $args );
}
/** Load Instances on demand **********************************************/
/**
* Get Checkout Class.
*
* @return WC_Checkout
*/
public function checkout() {
return WC_Checkout::instance();
}
/**
* Get gateways class
*
* @return WC_Payment_Gateways
*/
public function payment_gateways() {
return WC_Payment_Gateways::instance();
}
/**
* Get shipping class
*
* @return WC_Shipping
*/
public function shipping() {
return WC_Shipping::instance();
}
/**
* Email Class.
*
* @return WC_Email
*/
public function mailer() {
return WC_Emails::instance();
}
/** Deprecated methods *********************************************************/
/**
* @deprecated 2.1.0
* @param $image_size
* @return array
*/
public function get_image_size( $image_size ) {
_deprecated_function( 'Woocommerce->get_image_size', '2.1', 'wc_get_image_size()' );
return wc_get_image_size( $image_size );
}
/**
* @deprecated 2.1.0
* @return WC_Logger
*/
public function logger() {
_deprecated_function( 'Woocommerce->logger', '2.1', 'new WC_Logger()' );
return new WC_Logger();
}
/**
* @deprecated 2.1.0
* @return WC_Validation
*/
public function validation() {
_deprecated_function( 'Woocommerce->validation', '2.1', 'new WC_Validation()' );
return new WC_Validation();
}
/**
* @deprecated 2.1.0
* @param $post
* @return WC_Product
*/
public function setup_product_data( $post ) {
_deprecated_function( 'Woocommerce->setup_product_data', '2.1', 'wc_setup_product_data' );
return wc_setup_product_data( $post );
}
/**
* @deprecated 2.1.0
* @param $content
* @return string
*/
public function force_ssl( $content ) {
_deprecated_function( 'Woocommerce->force_ssl', '2.1', 'WC_HTTPS::force_https_url' );
return WC_HTTPS::force_https_url( $content );
}
/**
* @deprecated 2.1.0
* @param int $post_id
*/
public function clear_product_transients( $post_id = 0 ) {
_deprecated_function( 'Woocommerce->clear_product_transients', '2.1', 'wc_delete_product_transients' );
wc_delete_product_transients( $post_id );
}
/**
* @deprecated 2.1.0 Access via the WC_Inline_Javascript_Helper helper
* @param $code
*/
public function add_inline_js( $code ) {
_deprecated_function( 'Woocommerce->add_inline_js', '2.1', 'wc_enqueue_js' );
wc_enqueue_js( $code );
}
/**
* @deprecated 2.1.0
* @param $action
* @param bool $referer
* @param bool $echo
* @return string
*/
public function nonce_field( $action, $referer = true , $echo = true ) {
_deprecated_function( 'Woocommerce->nonce_field', '2.1', 'wp_nonce_field' );
return wp_nonce_field('woocommerce-' . $action, '_wpnonce', $referer, $echo );
}
/**
* @deprecated 2.1.0
* @param $action
* @param string $url
* @return string
*/
public function nonce_url( $action, $url = '' ) {
_deprecated_function( 'Woocommerce->nonce_url', '2.1', 'wp_nonce_url' );
return wp_nonce_url( $url , 'woocommerce-' . $action );
}
/**
* @deprecated 2.1.0
* @param $action
* @param string $method
* @param bool $error_message
* @return bool
*/
public function verify_nonce( $action, $method = '_POST', $error_message = false ) {
_deprecated_function( 'Woocommerce->verify_nonce', '2.1', 'wp_verify_nonce' );
if ( ! isset( $method[ '_wpnonce' ] ) ) {
return false;
}
return wp_verify_nonce( $method[ '_wpnonce' ], 'woocommerce-' . $action );
}
/**
* @deprecated 2.1.0
* @param $function
* @param array $atts
* @param array $wrapper
* @return string
*/
public function shortcode_wrapper( $function, $atts = array(), $wrapper = array( 'class' => 'woocommerce', 'before' => null, 'after' => null ) ) {
_deprecated_function( 'Woocommerce->shortcode_wrapper', '2.1', 'WC_Shortcodes::shortcode_wrapper' );
return WC_Shortcodes::shortcode_wrapper( $function, $atts, $wrapper );
}
/**
* @deprecated 2.1.0
* @return object
*/
public function get_attribute_taxonomies() {
_deprecated_function( 'Woocommerce->get_attribute_taxonomies', '2.1', 'wc_get_attribute_taxonomies' );
return wc_get_attribute_taxonomies();
}
/**
* @deprecated 2.1.0
* @param $name
* @return string
*/
public function attribute_taxonomy_name( $name ) {
_deprecated_function( 'Woocommerce->attribute_taxonomy_name', '2.1', 'wc_attribute_taxonomy_name' );
return wc_attribute_taxonomy_name( $name );
}
/**
* @deprecated 2.1.0
* @param $name
* @return string
*/
public function attribute_label( $name ) {
_deprecated_function( 'Woocommerce->attribute_label', '2.1', 'wc_attribute_label' );
return wc_attribute_label( $name );
}
/**
* @deprecated 2.1.0
* @param $name
* @return string
*/
public function attribute_orderby( $name ) {
_deprecated_function( 'Woocommerce->attribute_orderby', '2.1', 'wc_attribute_orderby' );
return wc_attribute_orderby( $name );
}
/**
* @deprecated 2.1.0
* @return array
*/
public function get_attribute_taxonomy_names() {
_deprecated_function( 'Woocommerce->get_attribute_taxonomy_names', '2.1', 'wc_get_attribute_taxonomy_names' );
return wc_get_attribute_taxonomy_names();
}
/**
* @deprecated 2.1.0
* @return array
*/
public function get_coupon_discount_types() {
_deprecated_function( 'Woocommerce->get_coupon_discount_types', '2.1', 'wc_get_coupon_types' );
return wc_get_coupon_types();
}
/**
* @deprecated 2.1.0
* @param string $type
* @return string
*/
public function get_coupon_discount_type( $type = '' ) {
_deprecated_function( 'Woocommerce->get_coupon_discount_type', '2.1', 'wc_get_coupon_type' );
return wc_get_coupon_type( $type );
}
/**
* @deprecated 2.1.0
* @param $class
*/
public function add_body_class( $class ) {
_deprecated_function( 'Woocommerce->add_body_class', '2.1' );
}
/**
* @deprecated 2.1.0
* @param $classes
*/
public function output_body_class( $classes ) {
_deprecated_function( 'Woocommerce->output_body_class', '2.1' );
}
/**
* @deprecated 2.1.0
* @param $error
*/
public function add_error( $error ) {
_deprecated_function( 'Woocommerce->add_error', '2.1', 'wc_add_notice' );
wc_add_notice( $error, 'error' );
}
/**
* @deprecated 2.1.0
* @param $message
*/
public function add_message( $message ) {
_deprecated_function( 'Woocommerce->add_message', '2.1', 'wc_add_notice' );
wc_add_notice( $message );
}
/**
* @deprecated 2.1.0
*/
public function clear_messages() {
_deprecated_function( 'Woocommerce->clear_messages', '2.1', 'wc_clear_notices' );
wc_clear_notices();
}
/**
* @deprecated 2.1.0
* @return int
*/
public function error_count() {
_deprecated_function( 'Woocommerce->error_count', '2.1', 'wc_notice_count' );
return wc_notice_count( 'error' );
}
/**
* @deprecated 2.1.0
* @return int
*/
public function message_count() {
_deprecated_function( 'Woocommerce->message_count', '2.1', 'wc_notice_count' );
return wc_notice_count( 'message' );
}
/**
* @deprecated 2.1.0
* @return mixed
*/
public function get_errors() {
_deprecated_function( 'Woocommerce->get_errors', '2.1', 'wc_get_notices( "error" )' );
return wc_get_notices( 'error' );
}
/**
* @deprecated 2.1.0
* @return mixed
*/
public function get_messages() {
_deprecated_function( 'Woocommerce->get_messages', '2.1', 'wc_get_notices( "success" )' );
return wc_get_notices( 'success' );
}
/**
* @deprecated 2.1.0
*/
public function show_messages() {
_deprecated_function( 'Woocommerce->show_messages', '2.1', 'wc_print_notices()' );
wc_print_notices();
}
/**
* @deprecated 2.1.0
*/
public function set_messages() {
_deprecated_function( 'Woocommerce->set_messages', '2.1' );
}
}
endif;
/**
* Returns the main instance of WC to prevent the need to use globals.
*
* @since 2.1
* @return WooCommerce
*/
function WC() {
return WooCommerce::instance();
}
// Global for backwards compatibility.
$GLOBALS['woocommerce'] = WC();