query = &new woocommerce_query(); // Query class, handles front-end queries and loops $this->customer = &new woocommerce_customer(); // Customer class, sorts out session data such as location $this->shipping = &new woocommerce_shipping(); // Shipping class. loads and stores shipping methods $this->cart = &new woocommerce_cart(); // Cart class, stores the cart contents $this->payment_gateways = &new woocommerce_payment_gateways(); // Payment gateways class. loads and stores payment methods $this->countries = &new woocommerce_countries(); // Countries class // Load messages $this->load_messages(); // Hooks add_filter('wp_redirect', array(&$this, 'redirect'), 1, 2); add_action( 'woocommerce_before_single_product', array(&$this, 'show_messages'), 10); add_action( 'woocommerce_before_shop_loop', array(&$this, 'show_messages'), 10); // Queue shipping and payment gateways add_action('plugins_loaded', array( &$this->shipping, 'init' ), 1); // Load shipping methods - some may be added by plugins add_action('plugins_loaded', array( &$this->payment_gateways, 'init' ), 1); // Load payment methods - some may be added by plugins } /*-----------------------------------------------------------------------------------*/ /* Helper functions */ /*-----------------------------------------------------------------------------------*/ /** * Get the plugin url */ function plugin_url() { if($this->plugin_url) return $this->plugin_url; if (is_ssl()) : return $this->plugin_url = str_replace('http://', 'https://', WP_PLUGIN_URL) . "/" . plugin_basename( dirname(dirname(__FILE__))); else : return $this->plugin_url = WP_PLUGIN_URL . "/" . plugin_basename( dirname(dirname(__FILE__))); endif; } /** * Get the plugin path */ function plugin_path() { if($this->plugin_path) return $this->plugin_path; return $this->plugin_path = WP_PLUGIN_DIR . "/" . plugin_basename( dirname(dirname(__FILE__))); } /** * Return the URL with https if SSL is on */ function force_ssl( $url ) { if (is_ssl()) $url = str_replace('http:', 'https:', $url); return $url; } /** * Get an image size * * Variable is filtered by woocommerce_get_image_size_{image_size} */ 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; endswitch; return apply_filters( 'woocommerce_get_image_size_'.$image_size, $return ); } /*-----------------------------------------------------------------------------------*/ /* Messages */ /*-----------------------------------------------------------------------------------*/ /** * Load Messages */ function load_messages() { if (isset($_SESSION['errors'])) $this->errors = $_SESSION['errors']; if (isset($_SESSION['messages'])) $this->messages = $_SESSION['messages']; unset($_SESSION['messages']); unset($_SESSION['errors']); } /** * Add an error */ function add_error( $error ) { $this->errors[] = $error; } /** * Add a message */ function add_message( $message ) { $this->messages[] = $message; } /** Clear messages and errors from the session data */ function clear_messages() { $this->errors = $this->messages = array(); unset($_SESSION['messages']); unset($_SESSION['errors']); } /** * Get error count */ function error_count() { return sizeof($this->errors); } /** * Get message count */ function message_count() { return sizeof($this->messages); } /** * Output the errors and messages */ function show_messages() { if (isset($this->errors) && sizeof($this->errors)>0) : echo '