get_image_size('shop_thumbnail_image_width'), $woocommerce->get_image_size('shop_thumbnail_image_height'), 'true' ); add_image_size( 'shop_catalog', $woocommerce->get_image_size('shop_catalog_image_width'), $woocommerce->get_image_size('shop_catalog_image_height'), 'true' ); add_image_size( 'shop_single', $woocommerce->get_image_size('shop_single_image_width'), $woocommerce->get_image_size('shop_single_image_height'), 'true' ); // Include template functions here so they are pluggable by themes include_once( 'woocommerce_template_functions.php' ); $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; if (is_admin()) : wp_enqueue_style( 'woocommerce_admin_styles', $woocommerce->plugin_url() . '/assets/css/admin.css' ); wp_enqueue_style( 'jquery-ui-style', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/smoothness/jquery-ui.css' ); else : // 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' : $woocommerce->plugin_url() . '/assets/css/woocommerce.css'; wp_register_style('woocommerce_frontend_styles', $css ); wp_enqueue_style( 'woocommerce_frontend_styles' ); endif; if (get_option('woocommerce_enable_lightbox')=='yes') wp_enqueue_style( 'woocommerce_fancybox_styles', $woocommerce->plugin_url() . '/assets/css/fancybox'.$suffix.'.css' ); endif; } /** * Set up Roles & Capabilities **/ add_action('init', 'woocommerce_init_roles'); function woocommerce_init_roles() { global $wp_roles; if (class_exists('WP_Roles')) if ( ! isset( $wp_roles ) ) $wp_roles = new WP_Roles(); if (is_object($wp_roles)) : // Customer role add_role('customer', __('Customer', 'woothemes'), array( 'read' => true, 'edit_posts' => false, 'delete_posts' => false )); // Shop manager role add_role('shop_manager', __('Shop Manager', 'woothemes'), array( 'read' => true, 'edit_posts' => true, 'delete_posts' => true, )); // Main Shop capabilities $wp_roles->add_cap( 'administrator', 'manage_woocommerce' ); $wp_roles->add_cap( 'shop_manager', 'manage_woocommerce' ); endif; } /** * Enqueue frontend scripts **/ function woocommerce_frontend_scripts() { global $woocommerce; $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; wp_register_script( 'woocommerce', $woocommerce->plugin_url() . '/assets/js/woocommerce'.$suffix.'.js', 'jquery', '1.0' ); wp_register_script( 'woocommerce_plugins', $woocommerce->plugin_url() . '/assets/js/woocommerce_plugins'.$suffix.'.js', 'jquery', '1.0' ); wp_register_script( 'fancybox', $woocommerce->plugin_url() . '/assets/js/fancybox'.$suffix.'.js', 'jquery', '1.0' ); wp_enqueue_script('jquery'); wp_enqueue_script('woocommerce_plugins'); wp_enqueue_script('woocommerce'); if (get_option('woocommerce_enable_lightbox')=='yes') wp_enqueue_script('fancybox'); /* Script variables */ $woocommerce_params = array( 'currency_symbol' => get_woocommerce_currency_symbol(), 'currency_pos' => get_option('woocommerce_currency_pos'), 'countries' => json_encode($woocommerce->countries->states), 'select_state_text' => __('Select a state…', 'woothemes'), 'state_text' => __('state', 'woothemes'), 'plugin_url' => $woocommerce->plugin_url(), 'ajax_url' => admin_url('admin-ajax.php'), 'get_variation_nonce' => wp_create_nonce("get-variation"), 'add_to_cart_nonce' => wp_create_nonce("add-to-cart"), 'update_order_review_nonce' => wp_create_nonce("update-order-review"), 'update_shipping_method_nonce' => wp_create_nonce("update-shipping-method"), 'option_guest_checkout' => get_option('woocommerce_enable_guest_checkout'), 'checkout_url' => admin_url('admin-ajax.php?action=woocommerce-checkout') ); if (isset($_SESSION['min_price'])) $woocommerce_params['min_price'] = $_SESSION['min_price']; if (isset($_SESSION['max_price'])) $woocommerce_params['max_price'] = $_SESSION['max_price']; if ( is_page(get_option('woocommerce_checkout_page_id')) || is_page(get_option('woocommerce_pay_page_id')) ) : $woocommerce_params['is_checkout'] = 1; else : $woocommerce_params['is_checkout'] = 0; endif; if ( is_cart() ) : $woocommerce_params['is_cart'] = 1; else : $woocommerce_params['is_cart'] = 0; endif; wp_localize_script( 'woocommerce', 'woocommerce_params', $woocommerce_params ); } add_action('template_redirect', 'woocommerce_frontend_scripts'); /** * WooCommerce conditionals **/ function is_woocommerce() { // Returns true if on a page which uses WooCommerce templates (cart and checkout are standard pages with shortcodes and thus are not included) if (is_shop() || is_product_category() || is_product_tag() || is_product()) return true; else return false; } function is_shop() { if (is_post_type_archive( 'product' ) || is_page(get_option('woocommerce_shop_page_id'))) return true; else return false; } function is_product_category() { return is_tax( 'product_cat' ); } function is_product_tag() { return is_tax( 'product_tag' ); } function is_product() { return is_singular( array('product') ); } function is_cart() { return is_page(get_option('woocommerce_cart_page_id')); } function is_checkout() { return is_page(get_option('woocommerce_checkout_page_id')); } function is_account_page() { if ( is_page(get_option('woocommerce_myaccount_page_id')) || is_page(get_option('woocommerce_edit_address_page_id')) || is_page(get_option('woocommerce_view_order_page_id')) || is_page(get_option('woocommerce_change_password_page_id')) ) return true; else return false; return is_page(get_option('woocommerce_myaccount_page_id')); } if (!function_exists('is_ajax')) { function is_ajax() { if ( isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' ) return true; else return false; } } /** * Force SSL (if enabled) **/ if (get_option('woocommerce_force_ssl_checkout')=='yes') add_action( 'wp', 'woocommerce_force_ssl'); function woocommerce_force_ssl() { if (is_checkout() && !is_ssl()) : wp_redirect( str_replace('http:', 'https:', get_permalink(get_option('woocommerce_checkout_page_id'))), 301 ); exit; endif; } /** * Force SSL for images **/ add_filter('post_thumbnail_html', 'woocommerce_force_ssl_images'); add_filter('widget_text', 'woocommerce_force_ssl_images'); add_filter('wp_get_attachment_url', 'woocommerce_force_ssl_images'); add_filter('wp_get_attachment_image_attributes', 'woocommerce_force_ssl_images'); add_filter('wp_get_attachment_url', 'woocommerce_force_ssl_images'); function woocommerce_force_ssl_images( $content ) { if (is_ssl()) : if (is_array($content)) : $content = array_map('woocommerce_force_ssl_images', $content); else : $content = str_replace('http:', 'https:', $content); endif; endif; return $content; } /** * IIS compatability fix/fallback **/ if (!isset($_SERVER['REQUEST_URI'])) { $_SERVER['REQUEST_URI'] = substr($_SERVER['PHP_SELF'],1 ); if (isset($_SERVER['QUERY_STRING'])) { $_SERVER['REQUEST_URI'].='?'.$_SERVER['QUERY_STRING']; } } /** * Fix 'insert into post' buttons for images **/ add_filter('get_media_item_args', 'woocommerce_allow_img_insertion'); function woocommerce_allow_img_insertion($vars) { $vars['send'] = true; // 'send' as in "Send to Editor" return($vars); } /** * Currency **/ function get_woocommerce_currency_symbol() { $currency = get_option('woocommerce_currency'); $currency_symbol = ''; switch ($currency) : case 'AUD' : case 'BRL' : case 'CAD' : case 'MXN' : case 'NZD' : case 'HKD' : case 'SGD' : case 'USD' : $currency_symbol = '$'; break; case 'EUR' : $currency_symbol = '€'; break; case 'JPY' : $currency_symbol = '¥'; break; case 'CZK' : case 'DKK' : case 'HUF' : case 'ILS' : case 'MYR' : case 'NOK' : case 'PHP' : case 'PLN' : case 'SEK' : case 'CHF' : case 'TWD' : case 'THB' : $currency_symbol = $currency; break; case 'GBP' : default : $currency_symbol = '£'; break; endswitch; return apply_filters('woocommerce_currency_symbol', $currency_symbol, $currency); } /** * Price Formatting **/ function woocommerce_price( $price, $args = array() ) { extract(shortcode_atts(array( 'ex_tax_label' => '0' ), $args)); $return = ''; $num_decimals = (int) get_option('woocommerce_price_num_decimals'); $currency_pos = get_option('woocommerce_currency_pos'); $currency_symbol = get_woocommerce_currency_symbol(); $price = number_format( (double) $price, $num_decimals, get_option('woocommerce_price_decimal_sep'), get_option('woocommerce_price_thousand_sep') ); switch ($currency_pos) : case 'left' : $return = $currency_symbol . $price; break; case 'right' : $return = $price . $currency_symbol; break; case 'left_space' : $return = $currency_symbol . ' ' . $price; break; case 'right_space' : $return = $price . ' ' . $currency_symbol; break; endswitch; if ($ex_tax_label && get_option('woocommerce_calc_taxes')=='yes') $return .= __(' (ex. tax)', 'woothemes'); return $return; } /** * Variation Formatting **/ function woocommerce_get_formatted_variation( $variation = '', $flat = false ) { global $woocommerce; if ($variation && is_array($variation)) : $return = ''; if (!$flat) : $return = '
: