Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 1785 lines (1505 sloc) 57.232 kb
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 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785
<?php
/**
* Plugin Name: WooCommerce
* Plugin URI: http://www.woothemes.com/woocommerce/
* Description: An e-commerce toolkit that helps you sell anything. Beautifully.
* Version: 1.7.0 beta
* Author: WooThemes
* Author URI: http://woothemes.com
* Requires at least: 3.3
* Tested up to: 3.4.2
*
* Text Domain: woocommerce
* Domain Path: /languages/
*
* @package WooCommerce
* @category Core
* @author WooThemes
*/

if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly

if ( ! class_exists( 'Woocommerce' ) ) {

/**
* Main WooCommerce Class
*
* Contains the main functions for WooCommerce, stores variables, and handles error messages
*
* @class Woocommerce
* @version 1.6.4
* @since 1.4
* @package WooCommerce
* @author WooThemes
*/
class Woocommerce {

/**
* @var string
*/
var $version = '1.7.0';

/**
* @var string
*/
var $plugin_url;

/**
* @var string
*/
var $plugin_path;

/**
* @var string
*/
var $template_url;

/**
* @var array
*/
var $errors = array();

/**
* @var array
*/
var $messages = array();

/**
* @var WC_Query
*/
var $query;

/**
* @var WC_Customer
*/
var $customer;

/**
* @var WC_Shipping
*/
var $shipping;

/**
* @var WC_Cart
*/
var $cart;

/**
* @var WC_Payment_Gateways
*/
var $payment_gateways;

/**
* @var WC_Countries
*/
var $countries;

/**
* @var WC_Email
*/
var $woocommerce_email;

/**
* @var WC_Checkout
*/
var $checkout;

/**
* @var WC_Integrations
*/
var $integrations;

/**
* @var array
*/
var $attribute_taxonomies;

/**
* @var array
*/
private $_body_classes = array();

/**
* @var string
*/
private $_inline_js = '';


/**
* WooCommerce Constructor.
*
* @access public
* @return void
*/
function __construct() {

// Start a PHP session, if not yet started
if ( ! session_id() )
session_start();

// Define version constant
define( 'WOOCOMMERCE_VERSION', $this->version );

// Include required files
$this->includes();

// Installation
if ( is_admin() && ! defined('DOING_AJAX') ) $this->install();

// Actions
add_action( 'init', array( &$this, 'init' ), 0 );
add_action( 'init', array( &$this, 'include_template_functions' ), 25 );
add_action( 'after_setup_theme', array( &$this, 'compatibility' ) );

// Loaded action
do_action( 'woocommerce_loaded' );
}


/**
* Include required core files.
*
* @access public
* @return void
*/
function includes() {
if ( is_admin() ) $this->admin_includes();
if ( defined('DOING_AJAX') ) $this->ajax_includes();
if ( ! is_admin() || defined('DOING_AJAX') ) $this->frontend_includes();

include( 'woocommerce-core-functions.php' ); // Contains core functions for the front/back end
include( 'widgets/widget-init.php' ); // Widget classes
include( 'classes/class-wc-countries.php' ); // Defines countries and states
include( 'classes/class-wc-order.php' ); // Single order class
include( 'classes/class-wc-product.php' ); // Product class
include( 'classes/class-wc-product-variation.php' ); // Product variation class
include( 'classes/class-wc-tax.php' ); // Tax class
include( 'classes/class-wc-settings-api.php' ); // Settings API

// Include Core Payment Gateways
include( 'classes/gateways/class-wc-payment-gateways.php' );
include( 'classes/gateways/class-wc-payment-gateway.php' );
include( 'classes/gateways/bacs/class-wc-bacs.php' );
include( 'classes/gateways/cheque/class-wc-cheque.php' );
include( 'classes/gateways/paypal/class-wc-paypal.php' );
include( 'classes/gateways/cod/class-wc-cod.php' );
include( 'classes/gateways/mijireh/class-wc-mijireh-checkout.php' );

// Include Core Shipping Methods
include( 'classes/shipping/class-wc-shipping.php' );
include( 'classes/shipping/class-wc-shipping-method.php' );
include( 'classes/shipping/class-wc-flat-rate.php' );
include( 'classes/shipping/class-wc-international-delivery.php' );
include( 'classes/shipping/class-wc-free-shipping.php' );
include( 'classes/shipping/class-wc-local-delivery.php' );
include( 'classes/shipping/class-wc-local-pickup.php' );

// Include Core Integrations
include( 'classes/integrations/class-wc-integration.php' );
include( 'classes/integrations/class-wc-integrations.php' );
include( 'classes/integrations/google-analytics/class-wc-google-analytics.php' );
include( 'classes/integrations/sharethis/class-wc-sharethis.php' );
include( 'classes/integrations/sharedaddy/class-wc-sharedaddy.php' );
include( 'classes/integrations/shareyourcart/class-wc-shareyourcart.php' );
}


/**
* Include required admin files.
*
* @access public
* @return void
*/
function admin_includes() {
include( 'admin/woocommerce-admin-init.php' ); // Admin section
}


/**
* Include required ajax files.
*
* @access public
* @return void
*/
function ajax_includes() {
include( 'woocommerce-ajax.php' ); // Ajax functions for admin and the front-end
}


/**
* Include required frontend files.
*
* @access public
* @return void
*/
function frontend_includes() {
include( 'woocommerce-hooks.php' ); // Template hooks used on the front-end
include( 'woocommerce-functions.php' ); // Contains functions for various front-end events
include( 'shortcodes/shortcode-init.php' ); // Init the shortcodes
include( 'classes/class-wc-query.php' ); // The main store queries
include( 'classes/class-wc-cart.php' ); // The main cart class
include( 'classes/class-wc-coupon.php' ); // Coupon class
include( 'classes/class-wc-customer.php' ); // Customer class
include( 'classes/abstracts/abstract-wc-session.php' ); // Abstract for session implementations
include( 'classes/class-wc-session-transients.php' ); // Transients implementation of the session class
}


/**
* Function used to Init WooCommerce Template Functions - This makes them pluggable by plugins and themes.
*
* @access public
* @return void
*/
function include_template_functions() {
include( 'woocommerce-template.php' );
}


/**
* Install upon activation.
*
* @access public
* @return void
*/
function install() {
register_activation_hook( __FILE__, 'activate_woocommerce' );
register_activation_hook( __FILE__, 'flush_rewrite_rules' );
if ( get_option('woocommerce_db_version') != $this->version )
add_action( 'init', 'install_woocommerce', 1 );
}


/**
* Init WooCommerce when WordPress Initialises.
*
* @access public
* @return void
*/
function init() {
//Before init action
do_action( 'before_woocommerce_init' );

// Set up localisation
$this->load_plugin_textdomain();

// Variables
$this->template_url = apply_filters( 'woocommerce_template_url', 'woocommerce/' );

// Load class instances
$this->payment_gateways = new WC_Payment_gateways(); // Payment gateways. Loads and stores payment methods
$this->shipping = new WC_Shipping(); // Shipping class. loads and stores shipping methods
$this->countries = new WC_Countries(); // Countries class
$this->integrations = new WC_Integrations(); // Integrations class

// Init shipping, payment gateways, and integrations
$this->shipping->init();
$this->payment_gateways->init();
$this->integrations->init();

// 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_Transients' );
$this->session = new $session_class();

// Class instances
$this->cart = new WC_Cart(); // Cart class, stores the cart contents
$this->customer = new WC_Customer(); // Customer class, handles data such as customer location
$this->query = new WC_Query(); // Query class, handles front-end queries and loops

// Load messages
$this->load_messages();

// Hooks
add_filter( 'template_include', array(&$this, 'template_loader') );
add_filter( 'comments_template', array(&$this, 'comments_template_loader') );
add_filter( 'wp_redirect', array(&$this, 'redirect'), 1, 2 );
add_action( 'template_redirect', array(&$this, 'buffer_checkout') );
add_action( 'wp_enqueue_scripts', array(&$this, 'frontend_scripts') );
add_action( 'wp_print_scripts', array(&$this, 'check_jquery'), 25 );
add_action( 'wp_head', array(&$this, 'generator') );
add_action( 'wp_head', array(&$this, 'wp_head') );
add_filter( 'body_class', array(&$this, 'output_body_class') );
add_action( 'wp_footer', array(&$this, 'output_inline_js'), 25 );
}

// Actions
add_action( 'the_post', array( &$this, 'setup_product_data' ) );
add_action( 'admin_footer', array( &$this, 'output_inline_js' ), 25 );

// 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_pending_to_processing', 'woocommerce_order_status_pending_to_on-hold', 'woocommerce_order_status_completed', 'woocommerce_new_customer_note' );

foreach ( $email_actions as $action )
add_action( $action, array( &$this, 'send_transactional_email') );

// Actions for SSL
if ( ! is_admin() || defined('DOING_AJAX') ) {
add_action( 'template_redirect', array( &$this, 'ssl_redirect' ) );

$filters = array( 'post_thumbnail_html', 'widget_text', 'wp_get_attachment_url', 'wp_get_attachment_image_attributes', 'wp_get_attachment_url', 'option_siteurl', 'option_homeurl', 'option_home', 'option_url', 'option_wpurl', 'option_stylesheet_url', 'option_template_url', 'script_loader_src', 'style_loader_src', 'template_directory_uri', 'stylesheet_directory_uri', 'site_url' );

foreach ( $filters as $filter )
add_filter( $filter, array( &$this, 'force_ssl') );
}

// Register globals for WC environment
$this->register_globals();

// Init WooCommerce taxonomies
$this->init_taxonomy();

// Init Images sizes
$this->init_image_sizes();

// Init styles
if ( ! is_admin() ) $this->init_styles();

// Trigger API requests
$this->api_requests();

// Init action
do_action( 'woocommerce_init' );
}


/**
* API request - Trigger any API requests (handy for third party plugins/gateways).
*
* @access public
* @return void
*/
function api_requests() {
if ( isset( $_GET['wc-api'] ) ) {
$api = strtolower( esc_attr( $_GET['wc-api'] ) );
do_action( 'woocommerce_api_' . $api );
}
}


/**
* Localisation.
*
* @access public
* @return void
*/
function load_plugin_textdomain() {
// Note: the first-loaded translation file overrides any following ones if the same translation is present
$locale = apply_filters( 'plugin_locale', get_locale(), 'woocommerce' );
$variable_lang = ( get_option( 'woocommerce_informal_localisation_type' ) == 'yes' ) ? 'informal' : 'formal';
load_textdomain( 'woocommerce', WP_LANG_DIR.'/woocommerce/woocommerce-'.$locale.'.mo' );
load_plugin_textdomain( 'woocommerce', false, dirname( plugin_basename( __FILE__ ) ).'/languages/'.$variable_lang );
load_plugin_textdomain( 'woocommerce', false, dirname( plugin_basename( __FILE__ ) ).'/languages' );
}


/**
* Load a template.
*
* Handles template usage so that we can use our own templates instead of the themes.
*
* Templates are in the 'templates' folder. woocommerce looks for theme
* overides in /theme/woocommerce/ by default
*
* For beginners, it also looks for a woocommerce.php template first. If the user adds
* this to the theme (containing a woocommerce() inside) this will be used for all
* woocommerce templates.
*
* @access public
* @param mixed $template
* @return string
*/
function template_loader( $template ) {

$find = array( 'woocommerce.php' );
$file = '';

if ( is_single() && get_post_type() == 'product' ) {

$file = 'single-product.php';
$find[] = $file;
$find[] = $this->template_url . $file;

} elseif ( is_tax( 'product_cat' ) || is_tax( 'product_tag' ) ) {

$term = get_queried_object();

$file = 'taxonomy-' . $term->taxonomy . '.php';
$find[] = 'taxonomy-' . $term->taxonomy . '-' . $term->slug . '.php';
$find[] = $this->template_url . 'taxonomy-' . $term->taxonomy . '-' . $term->slug . '.php';
$find[] = $file;
$find[] = $this->template_url . $file;

} elseif ( is_post_type_archive( 'product' ) || is_page( woocommerce_get_page_id( 'shop' ) ) ) {

$file = 'archive-product.php';
$find[] = $file;
$find[] = $this->template_url . $file;

}

if ( $file ) {
$template = locate_template( $find );
if ( ! $template ) $template = $this->plugin_path() . '/templates/' . $file;
}

return $template;
}


/**
* comments_template_loader function.
*
* @access public
* @param mixed $template
* @return string
*/
function comments_template_loader( $template ) {
if( get_post_type() !== 'product' ) return $template;

if (file_exists( STYLESHEETPATH . '/' . $this->template_url . 'single-product-reviews.php' ))
return STYLESHEETPATH . '/' . $this->template_url . 'single-product-reviews.php';
else
return $this->plugin_path() . '/templates/single-product-reviews.php';
}


/**
* Output buffering on the checkout allows gateways to do header redirects.
*
* @access public
* @return void
*/
function buffer_checkout() {
if ( is_checkout() ) ob_start();
}


/**
* Register WC environment globals.
*
* @access public
* @return void
*/
function register_globals() {
$GLOBALS['product'] = null;
}


/**
* When the_post is called, get product data too.
*
* @access public
* @param mixed $post
* @return WC_Product
*/
function setup_product_data( $post ) {
if ( is_int( $post ) ) $post = get_post( $post );
if ( $post->post_type !== 'product' ) return;
unset( $GLOBALS['product'] );
$GLOBALS['product'] = new WC_Product( $post->ID );
return $GLOBALS['product'];
}


/**
* Add Compatibility for various bits.
*
* @access public
* @return void
*/
function compatibility() {
// Post thumbnail support
if ( ! current_theme_supports( 'post-thumbnails' ) ) {
add_theme_support( 'post-thumbnails' );
remove_post_type_support( 'post', 'thumbnail' );
remove_post_type_support( 'page', 'thumbnail' );
} else {
add_post_type_support( 'product', 'thumbnail' );
}

// 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';
}


/**
* Redirect to https if Force SSL is enabled.
*
* @access public
* @return void
*/
function ssl_redirect() {
if ( get_option('woocommerce_force_ssl_checkout') == 'no' ) return;

if ( ! is_ssl() ) {
if ( is_checkout() ) {
wp_redirect( str_replace('http:', 'https:', get_permalink(woocommerce_get_page_id('checkout'))), 301 );
exit;
} elseif ( is_account_page() ) {
if ( 0 === strpos($_SERVER['REQUEST_URI'], 'http') ) {
wp_redirect( preg_replace( '|^http://|', 'https://', $_SERVER['REQUEST_URI'] ) );
exit;
} else {
wp_redirect( 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
exit;
}
exit;
}
} else {
// Break out of SSL if we leave the checkout/my accounts (anywhere but thanks)
if ( get_option('woocommerce_unforce_ssl_checkout') == 'yes' && $_SERVER['REQUEST_URI'] && ! is_checkout() && ! is_page( woocommerce_get_page_id('thanks') ) && ! is_ajax() && ! is_account_page() ) {
if ( 0 === strpos($_SERVER['REQUEST_URI'], 'http') ) {
wp_redirect( preg_replace( '|^https://|', 'http://', $_SERVER['REQUEST_URI'] ) );
exit;
} else {
wp_redirect( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
exit;
}
}
}
}


/**
* Output generator to aid debugging.
*
* @access public
* @return void
*/
function generator() {
echo "\n\n" . '<!-- WooCommerce Version -->' . "\n" . '<meta name="generator" content="WooCommerce ' . $this->version . '" />' . "\n\n";
}


/**
* Add body classes.
*
* @access public
* @return void
*/
function wp_head() {
$theme_name = ( function_exists( 'wp_get_theme' ) ) ? wp_get_theme() : get_current_theme();
$this->add_body_class( "theme-{$theme_name}" );

if ( is_woocommerce() ) $this->add_body_class('woocommerce');

if ( is_checkout() ) $this->add_body_class('woocommerce-checkout');

if ( is_cart() ) $this->add_body_class('woocommerce-cart');

if ( is_account_page() ) $this->add_body_class('woocommerce-account');

if ( is_woocommerce() || is_checkout() || is_cart() || is_account_page() || is_page( woocommerce_get_page_id('order_tracking') ) || is_page( woocommerce_get_page_id('thanks') ) ) $this->add_body_class('woocommerce-page');
}


/**
* Init WooCommerce taxonomies.
*
* @access public
* @return void
*/
function init_taxonomy() {

if ( post_type_exists('product') )
return;

/**
* Slugs
**/
$permalinks = get_option( 'woocommerce_permalinks' );
$shop_page_id = woocommerce_get_page_id( 'shop' );

// Base slug is also used for the product post type archive
$base_slug = $shop_page_id > 0 && get_page( $shop_page_id ) ? get_page_uri( $shop_page_id ) : 'shop';

// Get bases
$product_category_slug = empty( $permalinks['category_base'] ) ? _x( 'product-category', 'slug', 'woocommerce' ) : $permalinks['category_base'];
$product_tag_slug = empty( $permalinks['tag_base'] ) ? _x( 'product-tag', 'slug', 'woocommerce' ) : $permalinks['tag_base'];
$product_attribute_base = empty( $permalinks['attribute_base'] ) ? '' : $permalinks['attribute_base'];
$product_permalink = empty( $permalinks['product_base'] ) ? _x( 'product', 'slug', 'woocommerce' ) : $permalinks['product_base'];

if ( $product_permalink )
$rewrite = array( 'slug' => untrailingslashit( $product_permalink ), 'with_front' => false );
else
$rewrite = false;

$show_in_menu = current_user_can( 'manage_woocommerce' ) ? 'woocommerce' : true;

/**
* Taxonomies
**/
do_action( 'woocommerce_register_taxonomy' );

$admin_only_query_var = ( is_admin() ) ? true : false;

register_taxonomy( 'product_type',
array('product'),
array(
'hierarchical' => false,
'update_count_callback' => '_update_post_term_count',
'show_ui' => false,
'show_in_nav_menus' => false,
'query_var' => $admin_only_query_var,
'rewrite' => false
)
);
register_taxonomy( 'product_cat',
array('product'),
array(
'hierarchical' => true,
'update_count_callback' => 'woocommerce_manual_category_count',
'label' => __( 'Product Categories', 'woocommerce'),
'labels' => array(
'name' => __( 'Product Categories', 'woocommerce'),
'singular_name' => __( 'Product Category', 'woocommerce'),
'menu_name' => _x( 'Categories', 'Admin menu name', 'woocommerce' ),
'search_items' => __( 'Search Product Categories', 'woocommerce'),
'all_items' => __( 'All Product Categories', 'woocommerce'),
'parent_item' => __( 'Parent Product Category', 'woocommerce'),
'parent_item_colon' => __( 'Parent Product Category:', 'woocommerce'),
'edit_item' => __( 'Edit Product Category', 'woocommerce'),
'update_item' => __( 'Update Product Category', 'woocommerce'),
'add_new_item' => __( 'Add New Product Category', 'woocommerce'),
'new_item_name' => __( 'New Product Category Name', 'woocommerce')
),
'show_ui' => true,
'query_var' => true,
'capabilities' => array(
'manage_terms' => 'manage_product_terms',
'edit_terms' => 'edit_product_terms',
'delete_terms' => 'delete_product_terms',
'assign_terms' => 'assign_product_terms',
),
'rewrite' => array( 'slug' => $product_category_slug, 'with_front' => false, 'hierarchical' => true ),
)
);

register_taxonomy( 'product_tag',
array('product'),
array(
'hierarchical' => false,
'update_count_callback' => '_update_post_term_count',
'label' => __( 'Product Tags', 'woocommerce'),
'labels' => array(
'name' => __( 'Product Tags', 'woocommerce'),
'singular_name' => __( 'Product Tag', 'woocommerce'),
'menu_name' => _x( 'Tags', 'Admin menu name', 'woocommerce' ),
'search_items' => __( 'Search Product Tags', 'woocommerce'),
'all_items' => __( 'All Product Tags', 'woocommerce'),
'parent_item' => __( 'Parent Product Tag', 'woocommerce'),
'parent_item_colon' => __( 'Parent Product Tag:', 'woocommerce'),
'edit_item' => __( 'Edit Product Tag', 'woocommerce'),
'update_item' => __( 'Update Product Tag', 'woocommerce'),
'add_new_item' => __( 'Add New Product Tag', 'woocommerce'),
'new_item_name' => __( 'New Product Tag Name', 'woocommerce')
),
'show_ui' => true,
'query_var' => true,
'capabilities' => array(
'manage_terms' => 'manage_product_terms',
'edit_terms' => 'edit_product_terms',
'delete_terms' => 'delete_product_terms',
'assign_terms' => 'assign_product_terms',
),
'rewrite' => array( 'slug' => $product_tag_slug, 'with_front' => false ),
)
);

register_taxonomy( 'product_shipping_class',
array('product', 'product_variation'),
array(
'hierarchical' => true,
'update_count_callback' => '_update_post_term_count',
'label' => __( 'Shipping Classes', 'woocommerce'),
'labels' => array(
'name' => __( 'Shipping Classes', 'woocommerce'),
'singular_name' => __( 'Shipping Class', 'woocommerce'),
'menu_name' => _x( 'Shipping Classes', 'Admin menu name', 'woocommerce' ),
'search_items' => __( 'Search Shipping Classes', 'woocommerce'),
'all_items' => __( 'All Shipping Classes', 'woocommerce'),
'parent_item' => __( 'Parent Shipping Class', 'woocommerce'),
'parent_item_colon' => __( 'Parent Shipping Class:', 'woocommerce'),
'edit_item' => __( 'Edit Shipping Class', 'woocommerce'),
'update_item' => __( 'Update Shipping Class', 'woocommerce'),
'add_new_item' => __( 'Add New Shipping Class', 'woocommerce'),
'new_item_name' => __( 'New Shipping Class Name', 'woocommerce')
),
'show_ui' => true,
'show_in_nav_menus' => false,
'query_var' => $admin_only_query_var,
'capabilities' => array(
'manage_terms' => 'manage_product_terms',
'edit_terms' => 'edit_product_terms',
'delete_terms' => 'delete_product_terms',
'assign_terms' => 'assign_product_terms',
),
'rewrite' => false,
)
);

register_taxonomy( 'shop_order_status',
array('shop_order'),
array(
'hierarchical' => false,
'update_count_callback' => '_update_post_term_count',
'labels' => array(
'name' => __( 'Order statuses', 'woocommerce'),
'singular_name' => __( 'Order status', 'woocommerce'),
'search_items' => __( 'Search Order statuses', 'woocommerce'),
'all_items' => __( 'All Order statuses', 'woocommerce'),
'parent_item' => __( 'Parent Order status', 'woocommerce'),
'parent_item_colon' => __( 'Parent Order status:', 'woocommerce'),
'edit_item' => __( 'Edit Order status', 'woocommerce'),
'update_item' => __( 'Update Order status', 'woocommerce'),
'add_new_item' => __( 'Add New Order status', 'woocommerce'),
'new_item_name' => __( 'New Order status Name', 'woocommerce')
),
'show_ui' => false,
'show_in_nav_menus' => false,
'query_var' => $admin_only_query_var,
'rewrite' => false,
)
);

$attribute_taxonomies = $this->get_attribute_taxonomies();
if ( $attribute_taxonomies ) {
foreach ($attribute_taxonomies as $tax) {

$name = $this->attribute_taxonomy_name($tax->attribute_name);
$hierarchical = true;
if ($name) {

$label = ( isset( $tax->attribute_label ) && $tax->attribute_label ) ? $tax->attribute_label : $tax->attribute_name;

$show_in_nav_menus = apply_filters( 'woocommerce_attribute_show_in_nav_menus', false, $name );

register_taxonomy( $name,
array('product'),
array(
'hierarchical' => $hierarchical,
'update_count_callback' => '_update_post_term_count',
'labels' => array(
'name' => $label,
'singular_name' => $label,
'search_items' => __( 'Search', 'woocommerce') . ' ' . $label,
'all_items' => __( 'All', 'woocommerce') . ' ' . $label,
'parent_item' => __( 'Parent', 'woocommerce') . ' ' . $label,
'parent_item_colon' => __( 'Parent', 'woocommerce') . ' ' . $label . ':',
'edit_item' => __( 'Edit', 'woocommerce') . ' ' . $label,
'update_item' => __( 'Update', 'woocommerce') . ' ' . $label,
'add_new_item' => __( 'Add New', 'woocommerce') . ' ' . $label,
'new_item_name' => __( 'New', 'woocommerce') . ' ' . $label
),
'show_ui' => false,
'query_var' => true,
'capabilities' => array(
'manage_terms' => 'manage_product_terms',
'edit_terms' => 'edit_product_terms',
'delete_terms' => 'delete_product_terms',
'assign_terms' => 'assign_product_terms',
),
'show_in_nav_menus' => $show_in_nav_menus,
'rewrite' => array( 'slug' => $product_attribute_base . strtolower( sanitize_title( $tax->attribute_name ) ), 'with_front' => false, 'hierarchical' => $hierarchical ),
)
);

}
}
}

/**
* Post Types
**/
do_action( 'woocommerce_register_post_type' );

register_post_type( "product",
apply_filters( 'woocommerce_register_post_type_product',
array(
'labels' => array(
'name' => __( 'Products', 'woocommerce' ),
'singular_name' => __( 'Product', 'woocommerce' ),
'menu_name' => _x( 'Products', 'Admin menu name', 'woocommerce' ),
'add_new' => __( 'Add Product', 'woocommerce' ),
'add_new_item' => __( 'Add New Product', 'woocommerce' ),
'edit' => __( 'Edit', 'woocommerce' ),
'edit_item' => __( 'Edit Product', 'woocommerce' ),
'new_item' => __( 'New Product', 'woocommerce' ),
'view' => __( 'View Product', 'woocommerce' ),
'view_item' => __( 'View Product', 'woocommerce' ),
'search_items' => __( 'Search Products', 'woocommerce' ),
'not_found' => __( 'No Products found', 'woocommerce' ),
'not_found_in_trash' => __( 'No Products found in trash', 'woocommerce' ),
'parent' => __( 'Parent Product', 'woocommerce' )
),
'description' => __( 'This is where you can add new products to your store.', 'woocommerce' ),
'public' => true,
'show_ui' => true,
'capability_type' => 'product',
'map_meta_cap' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'hierarchical' => false, // Hierarcal causes memory issues - WP loads all records!
'rewrite' => $rewrite,
'query_var' => true,
'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail', 'comments', 'custom-fields', 'page-attributes' ),
'has_archive' => $base_slug,
'show_in_nav_menus' => true
)
)
);

// Sort out attachment urls (removed, breaks pagination) no alternatives add_rewrite_rule( '^' . $attachment_base . '([^/]*)/([^/]*)/([^/]*)/?', 'index.php?attachment=$matches[3]', 'top' );

register_post_type( "product_variation",
apply_filters( 'woocommerce_register_post_type_product_variation',
array(
'labels' => array(
'name' => __( 'Variations', 'woocommerce' ),
'singular_name' => __( 'Variation', 'woocommerce' ),
'add_new' => __( 'Add Variation', 'woocommerce' ),
'add_new_item' => __( 'Add New Variation', 'woocommerce' ),
'edit' => __( 'Edit', 'woocommerce' ),
'edit_item' => __( 'Edit Variation', 'woocommerce' ),
'new_item' => __( 'New Variation', 'woocommerce' ),
'view' => __( 'View Variation', 'woocommerce' ),
'view_item' => __( 'View Variation', 'woocommerce' ),
'search_items' => __( 'Search Variations', 'woocommerce' ),
'not_found' => __( 'No Variations found', 'woocommerce' ),
'not_found_in_trash' => __( 'No Variations found in trash', 'woocommerce' ),
'parent' => __( 'Parent Variation', 'woocommerce' )
),
'public' => true,
'show_ui' => false,
'capability_type' => 'product',
'map_meta_cap' => true,
'publicly_queryable' => false,
'exclude_from_search' => true,
'hierarchical' => false,
'rewrite' => false,
'query_var' => true,
'supports' => array( 'title', 'editor', 'custom-fields', 'page-attributes', 'thumbnail' ),
'show_in_nav_menus' => false
)
)
);

$menu_name = _x('Orders', 'Admin menu name', 'woocommerce');
if ( $order_count = woocommerce_processing_order_count() ) {
$menu_name .= " <span class='awaiting-mod update-plugins count-$order_count'><span class='processing-count'>" . number_format_i18n( $order_count ) . "</span></span>" ;
}

register_post_type( "shop_order",
apply_filters( 'woocommerce_register_post_type_shop_order',
array(
'labels' => array(
'name' => __( 'Orders', 'woocommerce' ),
'singular_name' => __( 'Order', 'woocommerce' ),
'add_new' => __( 'Add Order', 'woocommerce' ),
'add_new_item' => __( 'Add New Order', 'woocommerce' ),
'edit' => __( 'Edit', 'woocommerce' ),
'edit_item' => __( 'Edit Order', 'woocommerce' ),
'new_item' => __( 'New Order', 'woocommerce' ),
'view' => __( 'View Order', 'woocommerce' ),
'view_item' => __( 'View Order', 'woocommerce' ),
'search_items' => __( 'Search Orders', 'woocommerce' ),
'not_found' => __( 'No Orders found', 'woocommerce' ),
'not_found_in_trash' => __( 'No Orders found in trash', 'woocommerce' ),
'parent' => __( 'Parent Orders', 'woocommerce' ),
'menu_name' => $menu_name
),
'description' => __( 'This is where store orders are stored.', 'woocommerce' ),
'public' => true,
'show_ui' => true,
'capability_type' => 'shop_order',
'map_meta_cap' => true,
'publicly_queryable' => false,
'exclude_from_search' => true,
'show_in_menu' => $show_in_menu,
'hierarchical' => false,
'show_in_nav_menus' => false,
'rewrite' => false,
'query_var' => true,
'supports' => array( 'title', 'comments', 'custom-fields' ),
'has_archive' => false,
)
)
);

register_post_type( "shop_coupon",
apply_filters( 'woocommerce_register_post_type_shop_coupon',
array(
'labels' => array(
'name' => __( 'Coupons', 'woocommerce' ),
'singular_name' => __( 'Coupon', 'woocommerce' ),
'menu_name' => _x( 'Coupons', 'Admin menu name', 'woocommerce' ),
'add_new' => __( 'Add Coupon', 'woocommerce' ),
'add_new_item' => __( 'Add New Coupon', 'woocommerce' ),
'edit' => __( 'Edit', 'woocommerce' ),
'edit_item' => __( 'Edit Coupon', 'woocommerce' ),
'new_item' => __( 'New Coupon', 'woocommerce' ),
'view' => __( 'View Coupons', 'woocommerce' ),
'view_item' => __( 'View Coupon', 'woocommerce' ),
'search_items' => __( 'Search Coupons', 'woocommerce' ),
'not_found' => __( 'No Coupons found', 'woocommerce' ),
'not_found_in_trash' => __( 'No Coupons found in trash', 'woocommerce' ),
'parent' => __( 'Parent Coupon', 'woocommerce' )
),
'description' => __( 'This is where you can add new coupons that customers can use in your store.', 'woocommerce' ),
'public' => true,
'show_ui' => true,
'capability_type' => 'shop_coupon',
'map_meta_cap' => true,
'publicly_queryable' => false,
'exclude_from_search' => true,
'show_in_menu' => $show_in_menu,
'hierarchical' => false,
'rewrite' => false,
'query_var' => false,
'supports' => array( 'title' ),
'show_in_nav_menus' => false
)
)
);
}


/**
* Init images.
*
* @access public
* @return void
*/
function init_image_sizes() {
// Image sizes
$shop_thumbnail_crop = get_option('woocommerce_thumbnail_image_crop') == 1 ? true : false;
$shop_catalog_crop = get_option('woocommerce_catalog_image_crop') == 1 ? true : false;
$shop_single_crop = get_option('woocommerce_single_image_crop') == 1 ? true : false;

add_image_size( 'shop_thumbnail', $this->get_image_size('shop_thumbnail_image_width'), $this->get_image_size('shop_thumbnail_image_height'), $shop_thumbnail_crop );
add_image_size( 'shop_catalog', $this->get_image_size('shop_catalog_image_width'), $this->get_image_size('shop_catalog_image_height'), $shop_catalog_crop );
add_image_size( 'shop_single', $this->get_image_size('shop_single_image_width'), $this->get_image_size('shop_single_image_height'), $shop_single_crop );
}


/**
* Init frontend CSS.
*
* @access public
* @return void
*/
function init_styles() {

     // Optional front end css
if ( ( defined('WOOCOMMERCE_USE_CSS') && WOOCOMMERCE_USE_CSS ) || ( ! defined('WOOCOMMERCE_USE_CSS') && get_option('woocommerce_frontend_css') == 'yes') ) {
$css = file_exists( get_stylesheet_directory() . '/woocommerce/style.css' ) ? get_stylesheet_directory_uri() . '/woocommerce/style.css' : $this->plugin_url() . '/assets/css/woocommerce.css';

wp_enqueue_style( 'woocommerce_frontend_styles', $css );
}
}


/**
* Register/queue frontend scripts.
*
* @access public
* @return void
*/
function frontend_scripts() {
global $post;

$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
$lightbox_en = get_option('woocommerce_enable_lightbox') == 'yes' ? true : false;
$chosen_en = get_option( 'woocommerce_enable_chosen' ) == 'yes' ? true : false;
$frontend_script_path = $this->plugin_url() . '/assets/js/frontend/';

// Register any scipts for later use, or used as dependencies
wp_register_script( 'chosen', $this->plugin_url() . '/assets/js/chosen/chosen.jquery' . $suffix . '.js', array( 'jquery' ), $this->version, true );
wp_register_script( 'jquery-ui', $this->plugin_url() . '/assets/js/jquery-ui' . $suffix . '.js', array( 'jquery' ), $this->version, true );
wp_register_script( 'wc-jquery-plugins', $this->plugin_url() . '/assets/js/jquery-plugins' . $suffix . '.js', array( 'jquery' ), $this->version, true );
wp_register_script( 'wc-add-to-cart-variation', $frontend_script_path . 'add-to-cart-variation' . $suffix . '.js', array( 'jquery' ), $this->version, true );
wp_register_script( 'wc-single-product', $frontend_script_path . 'single-product' . $suffix . '.js', array( 'jquery' ), $this->version, true );

// Queue frontend scripts conditionally
if ( get_option( 'woocommerce_enable_ajax_add_to_cart' ) == 'yes' )
wp_enqueue_script( 'wc-add-to-cart', $frontend_script_path . 'add-to-cart' . $suffix . '.js', array( 'jquery' ), $this->version, true );

if ( is_cart() )
wp_enqueue_script( 'wc-cart', $frontend_script_path . 'cart' . $suffix . '.js', array( 'jquery' ), $this->version, true );

if ( is_checkout() )
wp_enqueue_script( 'wc-checkout', $frontend_script_path . 'checkout' . $suffix . '.js', array( 'jquery', 'woocommerce' ), $this->version, true );

if ( is_product() )
wp_enqueue_script( 'wc-single-product' );

if ( $lightbox_en && ( is_product() || ( ! empty( $post->post_content ) && strstr( $post->post_content, '[product_page' ) ) ) ) {
wp_enqueue_script( 'fancybox', $this->plugin_url() . '/assets/js/fancybox/fancybox' . $suffix . '.js', array( 'jquery' ), $this->version, true );
wp_enqueue_style( 'woocommerce_fancybox_styles', $this->plugin_url() . '/assets/css/fancybox.css' );
}

if ( $chosen_en && is_checkout() ) {
wp_enqueue_script( 'wc-chosen', $frontend_script_path . 'chosen-frontend' . $suffix . '.js', array( 'chosen' ), $this->version, true );
wp_enqueue_style( 'woocommerce_chosen_styles', $this->plugin_url() . '/assets/css/chosen.css' );
}

// Global frontend scripts
wp_enqueue_script( 'woocommerce', $frontend_script_path . 'woocommerce' . $suffix . '.js', array( 'jquery', 'wc-jquery-plugins' ), $this->version, true );

// Variables for JS scripts
$woocommerce_params = array(
'countries' => json_encode( $this->countries->get_allowed_country_states() ),
'select_state_text' => __( 'Select an option&hellip;', 'woocommerce' ),
'plugin_url' => $this->plugin_url(),
'ajax_url' => $this->ajax_url(),
'ajax_loader_url' => apply_filters( 'woocommerce_ajax_loader_url', $this->plugin_url() . '/assets/images/ajax-loader.gif' ),
'required_rating_text' => esc_attr__( 'Please select a rating', 'woocommerce' ),
'review_rating_required' => get_option( 'woocommerce_review_rating_required' ),
'required_text' => esc_attr__( 'required', 'woocommerce' ),
'update_order_review_nonce' => wp_create_nonce( "update-order-review" ),
'apply_coupon_nonce' => wp_create_nonce( "apply-coupon" ),
'option_guest_checkout' => get_option( 'woocommerce_enable_guest_checkout' ),
'checkout_url' => add_query_arg( 'action', 'woocommerce-checkout', $this->ajax_url() ),
'is_checkout' => is_page( woocommerce_get_page_id( 'checkout' ) ) ? 1 : 0,
'update_shipping_method_nonce' => wp_create_nonce( "update-shipping-method" ),
'add_to_cart_nonce' => wp_create_nonce( "add-to-cart" )
);

if ( is_checkout() || is_cart() )
$woocommerce_params['locale'] = json_encode( $this->countries->get_country_locale() );

wp_localize_script( 'woocommerce', 'woocommerce_params', apply_filters( 'woocommerce_params', $woocommerce_params ) );
}

/**
* WC requires jQuery 1.7 since it uses functions like .on() for events.
* If, by the time wp_print_scrips is called, jQuery is outdated (i.e not
* using the version in core) we need to deregister it and register the
* core version of the file.
*
* @access public
* @return void
*/
function check_jquery() {
global $wp_scripts;

// Enforce minimum version of jQuery
if ( isset( $wp_scripts->registered['jquery']->ver ) && $wp_scripts->registered['jquery']->ver < '1.7' ) {
wp_deregister_script( 'jquery' );
wp_register_script( 'jquery', '/wp-includes/js/jquery/jquery.js', array(), '1.7' );
wp_enqueue_script( 'jquery' );
}
}

/** Load Instances on demand **********************************************/

/**
* Get Checkout Class.
*
* @access public
* @return WC_Checkout
*/
function checkout() {
if ( ! class_exists('WC_Checkout') ) {
include( 'classes/class-wc-checkout.php' );
$this->checkout = new WC_Checkout();
}

return $this->checkout;
}


/**
* Get Logging Class.
*
* @access public
* @return WC_Logger
*/
function logger() {
if ( ! class_exists('WC_Logger') ) include( 'classes/class-wc-logger.php' );
return new WC_Logger();
}


/**
* Get Validation Class.
*
* @access public
* @return WC_Validation
*/
function validation() {
if ( ! class_exists('WC_Validation') ) include( 'classes/class-wc-validation.php' );
return new WC_Validation();
}


/**
* Init a coupon.
*
* @access public
* @param mixed $code
* @return WC_Coupon
*/
function coupon( $code ) {
if ( ! class_exists('WC_Coupon') ) include( 'classes/class-wc-coupon.php' );
return new WC_Coupon( $code );
}


/**
* Init the mailer and call the notifications for the current filter.
*
* @access public
* @param array $args (default: array())
* @return void
*/
function send_transactional_email( $args = array() ) {
$this->mailer();
do_action( current_filter() . '_notification', $args );
}


/**
* Email Class.
*
* @access public
* @return WC_Email
*/
function mailer() {
if ( empty( $this->woocommerce_email ) ) {
// Init mail class
if ( ! class_exists('WC_Emails') ) {
include_once( 'classes/emails/class-wc-emails.php' );
}
$this->woocommerce_email = new WC_Emails();
}
return $this->woocommerce_email;
}

/** Helper functions ******************************************************/

/**
* Get the plugin url.
*
* @access public
* @return string
*/
function plugin_url() {
if ( $this->plugin_url ) return $this->plugin_url;
return $this->plugin_url = plugins_url( basename( plugin_dir_path(__FILE__) ), basename( __FILE__ ) );
}


/**
* Get the plugin path.
*
* @access public
* @return string
*/
function plugin_path() {
if ( $this->plugin_path ) return $this->plugin_path;

return $this->plugin_path = untrailingslashit( plugin_dir_path( __FILE__ ) );
}


/**
* Get Ajax URL.
*
* @access public
* @return string
*/
function ajax_url() {
return str_replace( array('https:', 'http:'), '', admin_url( 'admin-ajax.php' ) );
}


/**
* Return the URL with https if SSL is on.
*
* @access public
* @param string/array $content
* @return string/array
*/
function force_ssl( $content ) {
if ( is_ssl() ) {
if ( is_array($content) )
$content = array_map( array( &$this, 'force_ssl' ) , $content );
else
$content = str_replace( 'http:', 'https:', $content );
}
return $content;
}


/**
* Get an image size.
*
* Variable is filtered by woocommerce_get_image_size_{image_size}
*
* @access public
* @param mixed $image_size
* @return string
*/
function get_image_size( $image_size ) {
$return = '';
switch ( $image_size ) {
case "shop_thumbnail_image_width" : $return = get_option('woocommerce_thumbnail_image_width'); break;
case "shop_thumbnail_image_height" : $return = get_option('woocommerce_thumbnail_image_height'); break;
case "shop_catalog_image_width" : $return = get_option('woocommerce_catalog_image_width'); break;
case "shop_catalog_image_height" : $return = get_option('woocommerce_catalog_image_height'); break;
case "shop_single_image_width" : $return = get_option('woocommerce_single_image_width'); break;
case "shop_single_image_height" : $return = get_option('woocommerce_single_image_height'); break;
}
return apply_filters( 'woocommerce_get_image_size_' . $image_size, $return );
}

/** Messages ****************************************************************/

/**
* Load Messages.
*
* @access public
* @return void
*/
function load_messages() {
$this->errors = $this->session->errors;
$this->messages = $this->session->messages;
unset( $this->session->errors, $this->session->messages );

// Load errors from querystring
if ( isset( $_GET['wc_error'] ) )
$this->add_error( esc_attr( $_GET['wc_error'] ) );
}


/**
* Add an error.
*
* @access public
* @param string $error
* @return void
*/
function add_error( $error ) {
$this->errors[] = apply_filters( 'woocommerce_add_error', $error );
}


/**
* Add a message.
*
* @access public
* @param string $message
* @return void
*/
function add_message( $message ) {
$this->messages[] = apply_filters( 'woocommerce_add_message', $message );
}


/**
* Clear messages and errors from the session data.
*
* @access public
* @return void
*/
function clear_messages() {
$this->errors = $this->messages = array();
unset( $this->session->errors, $this->session->messages );
}


/**
* error_count function.
*
* @access public
* @return int
*/
function error_count() {
return sizeof( $this->errors );
}


/**
* Get message count.
*
* @access public
* @return int
*/
function message_count() {
return sizeof( $this->messages );
}


/**
* Get errors.
*
* @access public
* @return array
*/
function get_errors() {
return (array) $this->errors;
}


/**
* Get messages.
*
* @access public
* @return array
*/
function get_messages() {
return (array) $this->messages;
}


/**
* Output the errors and messages.
*
* @access public
* @return void
*/
function show_messages() {
woocommerce_show_messages();
}


/**
* Set session data for messages.
*
* @access public
* @return void
*/
function set_messages() {
$this->session->errors = $this->errors;
$this->session->messages = $this->messages;
}


/**
* Redirection hook which stores messages into session data.
*
* @access public
* @param mixed $location
* @param mixed $status
* @return string
*/
function redirect( $location, $status ) {
$this->set_messages();

return apply_filters( 'woocommerce_redirect', $location );
}

/** Attribute Helpers ****************************************************************/

/**
* Get attribute taxonomies.
*
* @access public
* @return object
*/
function get_attribute_taxonomies() {
global $wpdb;
if ( ! $this->attribute_taxonomies )
$this->attribute_taxonomies = $wpdb->get_results("SELECT * FROM " . $wpdb->prefix . "woocommerce_attribute_taxonomies;" );
return apply_filters( 'woocommerce_attribute_taxonomies', $this->attribute_taxonomies );
}


/**
* Get a product attributes name.
*
* @access public
* @param mixed $name
* @return string
*/
function attribute_taxonomy_name( $name ) {
return 'pa_' . sanitize_title( $name );
}


/**
* Get a product attributes label.
*
* @access public
* @param mixed $name
* @return string
*/
function attribute_label( $name ) {
global $wpdb;

if ( strstr( $name, 'pa_' ) ) {
$name = str_replace( 'pa_', '', sanitize_title( $name ) );

$label = $wpdb->get_var( $wpdb->prepare( "SELECT attribute_label FROM " . $wpdb->prefix . "woocommerce_attribute_taxonomies WHERE attribute_name = %s;", $name ) );

if ( ! $label ) $label = ucfirst( $name );
} else {
$label = $name;
}

return apply_filters( 'woocommerce_attribute_label', $label, $name );
}


/**
* Get a product attributes orderby setting.
*
* @access public
* @param mixed $name
* @return string
*/
function attribute_orderby( $name ) {
global $wpdb;

$name = str_replace( 'pa_', '', sanitize_title( $name ) );

$orderby = $wpdb->get_var( $wpdb->prepare( "SELECT attribute_orderby FROM " . $wpdb->prefix . "woocommerce_attribute_taxonomies WHERE attribute_name = %s;", $name ) );

return apply_filters( 'woocommerce_attribute_orderby', $orderby, $name );
}



/**
* Get an array of product attribute taxonomies.
*
* @access public
* @return array
*/
function get_attribute_taxonomy_names() {
$taxonomy_names = array();
$attribute_taxonomies = $this->get_attribute_taxonomies();
if ( $attribute_taxonomies ) {
foreach ( $attribute_taxonomies as $tax ) {
$taxonomy_names[] = $this->attribute_taxonomy_name( strtolower( sanitize_title( $tax->attribute_name ) ) );
}
}
return $taxonomy_names;
}

/** Coupon Helpers ********************************************************/

/**
* Get coupon types.
*
* @access public
* @return array
*/
function get_coupon_discount_types() {
if ( ! isset($this->coupon_discount_types ) ) {
$this->coupon_discount_types = apply_filters( 'woocommerce_coupon_discount_types', array(
     'fixed_cart' => __('Cart Discount', 'woocommerce'),
     'percent' => __('Cart % Discount', 'woocommerce'),
     'fixed_product' => __('Product Discount', 'woocommerce'),
     'percent_product' => __('Product % Discount', 'woocommerce')
     ) );
}
return $this->coupon_discount_types;
}


/**
* Get a coupon type's name.
*
* @access public
* @param string $type (default: '')
* @return string
*/
function get_coupon_discount_type( $type = '' ) {
$types = (array) $this->get_coupon_discount_types();
if ( isset( $types[$type] ) ) return $types[$type];
}

/** Nonces ****************************************************************/

/**
* Return a nonce field.
*
* @access public
* @param mixed $action
* @param bool $referer (default: true)
* @param bool $echo (default: true)
* @return void
*/
function nonce_field( $action, $referer = true , $echo = true ) {
return wp_nonce_field('woocommerce-' . $action, '_n', $referer, $echo );
}


/**
* Return a url with a nonce appended.
*
* @access public
* @param mixed $action
* @param string $url (default: '')
* @return string
*/
function nonce_url( $action, $url = '' ) {
return add_query_arg( '_n', wp_create_nonce( 'woocommerce-' . $action ), $url );
}


/**
* Check a nonce and sets woocommerce error in case it is invalid.
*
* To fail silently, set the error_message to an empty string
*
* @access public
* @param string $name the nonce name
* @param string $action then nonce action
* @param string $method the http request method _POST, _GET or _REQUEST
* @param string $error_message custom error message, or false for default message, or an empty string to fail silently
* @return bool
*/
function verify_nonce( $action, $method='_POST', $error_message = false ) {

$name = '_n';
$action = 'woocommerce-' . $action;

if ( $error_message === false ) $error_message = __('Action failed. Please refresh the page and retry.', 'woocommerce');

if ( ! in_array( $method, array( '_GET', '_POST', '_REQUEST' ) ) ) $method = '_POST';

if ( isset($_REQUEST[$name] ) && wp_verify_nonce( $_REQUEST[$name], $action ) ) return true;

if ( $error_message ) $this->add_error( $error_message );

return false;
}

/** Shortcode Helpers *********************************************************/

/**
* Shortcode Wrapper
*
* @access public
* @param mixed $function
* @param array $atts (default: array())
* @return string
*/
function shortcode_wrapper( $function, $atts = array() ) {
ob_start();
call_user_func( $function, $atts );
return ob_get_clean();
}

/** Cache Helpers *********************************************************/

/**
* Sets a constant preventing some caching plugins from caching a page. Used on dynamic pages
*
* @access public
* @return void
*/
function nocache() {
if ( ! defined('DONOTCACHEPAGE') ) define("DONOTCACHEPAGE", "true"); // WP Super Cache constant
}


/**
* Sets a cookie when the cart has something in it. Can be used by hosts to prevent caching if set.
*
* @access public
* @param mixed $set
* @return void
*/
function cart_has_contents_cookie( $set ) {
if ( ! headers_sent() ) {
if ($set)
setcookie( "woocommerce_items_in_cart", "1", 0, COOKIEPATH, COOKIE_DOMAIN, false );
else
setcookie( "woocommerce_items_in_cart", "0", time() - 3600, COOKIEPATH, COOKIE_DOMAIN, false );
}
}

/**
* mfunc_wrapper function.
*
* Wraps a function in mfunc to keep it dynamic.
*
* If running WP Super Cache this checks for late_init (because functions calling this require WP to be loaded)
*
* @access public
* @param mixed $function
* @return void
*/
function mfunc_wrapper( $mfunction, $function, $args ) {
global $wp_super_cache_late_init;

if ( is_null( $wp_super_cache_late_init ) || $wp_super_cache_late_init == 1 ) {
echo '<!--mfunc ' . $mfunction . ' -->';
$function( $args );
echo '<!--/mfunc-->';
} else {
$function( $args );
}
}

/** Transients ************************************************************/

/**
* Clear all transients cache for product data.
*
* @access public
* @param int $post_id (default: 0)
* @return void
*/
function clear_product_transients( $post_id = 0 ) {
global $wpdb;

$post_id = absint( $post_id );

$wpdb->show_errors();

// Clear core transients
$transients_to_clear = array(
'wc_products_onsale',
'wc_hidden_product_ids',
'wc_hidden_product_ids_search'
);

foreach( $transients_to_clear as $transient ) {
delete_transient( 'wc_products_onsale' );
$wpdb->query( $wpdb->prepare( "DELETE FROM `$wpdb->options` WHERE `option_name` = %s", '_transient_' . $transient ) );
}

// Clear transients for which we don't have the name
$wpdb->query( "DELETE FROM `$wpdb->options` WHERE `option_name` LIKE ('_transient_wc_uf_pid_%')" );
$wpdb->query( "DELETE FROM `$wpdb->options` WHERE `option_name` LIKE ('_transient_wc_ln_count_%')" );
$wpdb->query( "DELETE FROM `$wpdb->options` WHERE `option_name` LIKE ('_transient_wc_ship_%')" );

// Clear product specific transients
$post_transients_to_clear = array(
'wc_product_children_ids_',
'wc_product_total_stock_',
'wc_average_rating_',
'wc_product_type_'
);

if ( $post_id > 0 ) {

foreach( $post_transients_to_clear as $transient ) {
delete_transient( $transient . $post_id );
$wpdb->query( $wpdb->prepare( "DELETE FROM `$wpdb->options` WHERE `option_name` = %s", '_transient_' . $transient . $post_id ) );
}

clean_post_cache( $post_id );

} else {

foreach( $post_transients_to_clear as $transient ) {
$wpdb->query( $wpdb->prepare( "DELETE FROM `$wpdb->options` WHERE `option_name` = %s", '_transient_' . $transient . '%' ) );
}

}
}

/** Body Classes **********************************************************/

/**
* Add a class to the webpage body.
*
* @access public
* @param string $class
* @return void
*/
function add_body_class( $class ) {
$this->_body_classes[] = sanitize_html_class( strtolower($class) );
}

/**
* Output classes on the body tag.
*
* @access public
* @param mixed $classes
* @return array
*/
function output_body_class( $classes ) {
if ( sizeof( $this->_body_classes ) > 0 ) $classes = array_merge( $classes, $this->_body_classes );

if ( is_singular('product') ) {
$key = array_search( 'singular', $classes );
if ( $key !== false ) unset( $classes[$key] );
}

return $classes;
}

/** Inline JavaScript Helper **********************************************/

/**
* Add some JavaScript inline to be output in the footer.
*
* @access public
* @param string $code
* @return void
*/
function add_inline_js( $code ) {
$this->_inline_js .= "\n" . $code . "\n";
}

/**
* Output any queued inline JS.
*
* @access public
* @return void
*/
function output_inline_js() {
if ( $this->_inline_js ) {

echo "<!-- WooCommerce JavaScript-->\n<script type=\"text/javascript\">\njQuery(document).ready(function($) {";

echo $this->_inline_js;

echo "});\n</script>\n";

$this->_inline_js = '';
}
}
}

/**
* Init woocommerce class
*/
$GLOBALS['woocommerce'] = new Woocommerce();

} // class_exists check
Something went wrong with that request. Please try again.