Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- add_filter('woocommerce_enqueue_styles', '__return_false');
- if (!function_exists('woocommerce_enabled')) {
- function woocommerce_enabled() {
- if (class_exists('woocommerce'))
- return true;
- return false;
- }
- }
- /* ====== Remove Actions ====== */
- remove_action('woocommerce_before_shop_loop', 'woocommerce_result_count', 20);
- remove_action('woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 30);
- /* ====== Remove Page Title ====== */
- add_filter('woocommerce_show_page_title', 'title_none');
- if (!function_exists('title_none')) {
- function title_none() {
- return false;
- }
- }
- /* ====== Close Div Tag ====== */
- if (!function_exists('tw_close_div')) {
- function tw_close_div() {
- echo "</div>";
- }
- }
- /* ====== Change Wrapper Begin ====== */
- remove_action('woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10);
- add_action('woocommerce_before_main_content', 'tw_woocommerce_output_content_wrapper', 10);
- if (!function_exists('tw_woocommerce_output_content_wrapper')) {
- function tw_woocommerce_output_content_wrapper() {
- echo '<div class="container">';
- echo "<div class='row'>";
- if (is_singular('product')) {
- if (tw_option('woo_singlesidebar'))
- echo "<div class='span9'>";
- else
- echo "<div class='span12'>";
- } else if (tw_option('woo_shopsidebar')) {
- echo "<div class='span9'>";
- } else {
- echo "<div class='span12'>";
- }
- }
- }
- /* ====== Change Wrapper End ====== */
- remove_action('woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10);
- add_action('woocommerce_after_main_content', 'tw_close_div', 10);
- /* ====== Added div loop product before ====== */
- add_action('woocommerce_before_shop_loop_item', 'tw_loop_product_before', 5);
- if (!function_exists('tw_loop_product_before')) {
- function tw_loop_product_before() {
- echo "<div class='tw_product_container'>";
- }
- }
- add_action('woocommerce_after_shop_loop_item', 'tw_close_div', 1000);
- add_action('woocommerce_before_shop_loop_item_title', 'tw_loop_product_title_container', 20);
- if (!function_exists('tw_loop_product_title_container')) {
- function tw_loop_product_title_container() {
- echo "<div class='tw_product_header'>";
- }
- }
- add_action('woocommerce_after_shop_loop_item_title', 'tw_close_div', 1000);
- /* ====== Change Pagination ====== */
- remove_action('woocommerce_after_shop_loop', 'woocommerce_pagination', 10);
- add_action('woocommerce_after_shop_loop', 'pagination', 10);
- /* ====== Change Breadcrumbs ====== */
- remove_action('woocommerce_before_main_content', 'woocommerce_breadcrumb', 20, 0);
- add_filter('woocommerce_breadcrumb_defaults', 'tw_woocommerce_breadcrumbs');
- if (!function_exists('tw_woocommerce_breadcrumbs')) {
- function tw_woocommerce_breadcrumbs() {
- return array(
- 'delimiter' => ' / ',
- 'wrap_before' => '<div class="tw-breadcrumb pull-right" itemprop="breadcrumb">',
- 'wrap_after' => '</div>',
- 'before' => '<span>',
- 'after' => '</span>',
- 'home' => _x('Home', 'breadcrumb', 'themewaves'),
- );
- }
- }
- /* ====== Change Products Columns ====== */
- add_filter('loop_shop_columns', 'loop_columns');
- if (!function_exists('loop_columns')) {
- function loop_columns() {
- if (tw_option('woo_shopsidebar'))
- return 3; // 3 products per row
- return 4; // 3 products per row
- }
- }
- /* ====== Product thumbs columns ====== */
- add_filter('woocommerce_product_thumbnails_columns', 'tw_woocommerce_product_thumbs_columns');
- if (!function_exists('tw_woocommerce_product_thumbs_columns')) {
- function tw_woocommerce_product_thumbs_columns() {
- return 4;
- }
- }
- /* ====== Product single thumb size ====== */
- add_image_size('tw_shop_single', 260, 260, false);
- add_filter('single_product_large_thumbnail_size', 'tw_single_product_large_thumb');
- if (!function_exists('tw_single_product_large_thumb')) {
- function tw_single_product_large_thumb() {
- return 'tw_shop_single';
- }
- }
- /* ====== Change Thumbnail ====== */
- remove_action('woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10);
- add_action('woocommerce_before_shop_loop_item_title', 'tw_woocommerce_thumb', 10);
- if (!function_exists('tw_woocommerce_thumb')) {
- function tw_woocommerce_thumb() {
- $id = get_the_ID();
- $width = 300;
- echo "<div class='thumbnail_container'>";
- echo post_image_show($width);
- echo tw_woocommerce_gallery_first_thumb($id, $width);
- echo "<span class='cart-load'></span>";
- echo "</div>";
- }
- }
- if (!function_exists('tw_woocommerce_gallery_first_thumb')) {
- function tw_woocommerce_gallery_first_thumb($id, $width) {
- $gallery = get_post_meta($id, '_product_image_gallery', true);
- if (!empty($gallery)) {
- $woo_gallery = explode(',', $gallery);
- $image_id = $woo_gallery[0];
- $image = aq_resize(wp_get_attachment_url($image_id), $width, "", true);
- $alt = get_post_meta($image_id, '_wp_attachment_image_alt', true);
- $alt = !empty($alt) ? $alt : get_the_title();
- if (!empty($image))
- return '<img src="' . $image . '" class="product-hover-thumb" alt="' . $alt . '">';
- }
- }
- }
- /* ====== Change Add To Cart ====== */
- remove_action('woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10);
- add_action('woocommerce_after_shop_loop_item', 'tw_add_cart_button', 16);
- if (!function_exists('tw_add_cart_button')) {
- function tw_add_cart_button() {
- global $product;
- if ($product->product_type == 'bundle') {
- $product = new WC_Product_Bundle($product->id);
- }
- ob_start();
- woocommerce_template_loop_add_to_cart();
- $output = ob_get_clean();
- if ($product->product_type == 'variable' && empty($output)) {
- $output = "<a class='add_to_cart_button product_type_variable button' href='" . get_permalink($product->id) . "'>" . __('Select options', 'themewaves') . "</a>";
- }
- if ($product->product_type == 'simple') {
- $output .= "<a class='show_details_button button' href='" . get_permalink($product->id) . "'>" . __('Show Details', 'themewaves') . "</a>";
- }
- if ($output)
- echo "<div class='tw_cart_buttons button'>$output</div>";
- }
- }
- /* ====== Products per page ====== */
- add_filter('loop_shop_per_page', 'tw_products_count');
- if (!function_exists('tw_products_count')) {
- function tw_products_count() {
- global $tw_woocommerce;
- if (!empty($tw_woocommerce['products_per_page']))
- return $tw_woocommerce['products_per_page'];
- return tw_option('woo_per_page');
- }
- }
- /* ====== Products sort ====== */
- add_action('woocommerce_before_shop_loop', 'tw_woocommerce_sorting', 20);
- if (!function_exists('tw_woocommerce_sorting')) {
- function tw_woocommerce_sorting() {
- global $tw_woocommerce;
- if (!tw_option('woo_sorting'))
- return false;
- $product_order['default'] = __("Default Order", "themewaves");
- $product_order['title'] = __("Name", "themewaves");
- $product_order['price'] = __("Price", "themewaves");
- $product_order['date'] = __("Date", "themewaves");
- $product_order['popularity'] = __("Popularity", "themewaves");
- $product_sort['asc'] = __("Click to order products ascending", "themewaves");
- $product_sort['desc'] = __("Click to order products descending", "themewaves");
- $per_page_string = __("Products per page", "themewaves");
- $per_page = tw_option('woo_per_page');
- if (!$per_page)
- $per_page = get_option('posts_per_page');
- parse_str($_SERVER['QUERY_STRING'], $params);
- $po_key = !empty($tw_woocommerce['product_order']) ? $tw_woocommerce['product_order'] : 'default';
- $ps_key = !empty($tw_woocommerce['product_sort']) ? $tw_woocommerce['product_sort'] : 'asc';
- $pc_key = !empty($tw_woocommerce['product_count']) ? $tw_woocommerce['product_count'] : $per_page;
- $ps_key = strtolower($ps_key);
- //generate markup
- $output = "";
- $output .= "<div class='tw-product-ordering'>";
- $output .= " <ul class='product-order'>";
- $output .= " <li><span class='tw-order-current'>" . __("Sort by", "themewaves") . " <span>" . $product_order[$po_key] . "</span><i class='fa fa-sort'></i></span>";
- $output .= " <ul>";
- $output .= " <li><a href='" . avia_woo_build_query_string($params, 'product_order', 'default') . "'> <span class='avia-bullet'></span>" . $product_order['default'] . "</a></li>";
- $output .= " <li><a href='" . avia_woo_build_query_string($params, 'product_order', 'title') . "'> <span class='avia-bullet'></span>" . $product_order['title'] . "</a></li>";
- $output .= " <li><a href='" . avia_woo_build_query_string($params, 'product_order', 'price') . "'> <span class='avia-bullet'></span>" . $product_order['price'] . "</a></li>";
- $output .= " <li><a href='" . avia_woo_build_query_string($params, 'product_order', 'date') . "'> <span class='avia-bullet'></span>" . $product_order['date'] . "</a></li>";
- $output .= " <li><a href='" . avia_woo_build_query_string($params, 'product_order', 'popularity') . "'> <span class='avia-bullet'></span>" . $product_order['popularity'] . "</a></li>";
- $output .= " </ul>";
- $output .= " </li>";
- $output .= " </ul>";
- $output .= " <ul class='product-count'>";
- $output .= " <li><span class='tw-order-current'>" . __("Display", "themewaves") . " <span>" . $pc_key . " " . $per_page_string . "</span><i class='fa fa-sort'></i></span>";
- $output .= " <ul>";
- $output .= " <li><a href='" . avia_woo_build_query_string($params, 'product_count', $per_page) . "'> <span class='avia-bullet'></span>" . $per_page . " " . $per_page_string . "</a></li>";
- $output .= " <li><a href='" . avia_woo_build_query_string($params, 'product_count', $per_page * 2) . "'> <span class='avia-bullet'></span>" . ($per_page * 2) . " " . $per_page_string . "</a></li>";
- $output .= " <li><a href='" . avia_woo_build_query_string($params, 'product_count', $per_page * 3) . "'> <span class='avia-bullet'></span>" . ($per_page * 3) . " " . $per_page_string . "</a></li>";
- $output .= " </ul>";
- $output .= " </li>";
- $output .= " </ul>";
- $output .= " <ul class='product-sort'>";
- $output .= " <li>";
- if ($ps_key == 'desc')
- $output .= "<a title='" . $product_sort['asc'] . "' class='sort-asc' href='" . avia_woo_build_query_string($params, 'product_sort', 'asc') . "'><i class='fa fa-long-arrow-down'></i></a>";
- if ($ps_key == 'asc')
- $output .= "<a title='" . $product_sort['desc'] . "' class='sort-desc' href='" . avia_woo_build_query_string($params, 'product_sort', 'desc') . "'><i class='fa fa-long-arrow-up'></i></a>";
- $output .= " </li>";
- $output .= " </ul>";
- $output .= "</div>";
- echo $output;
- }
- }
- //helper function to build the query strings for the catalog ordering menu
- if (!function_exists('avia_woo_build_query_string')) {
- function avia_woo_build_query_string($params = array(), $overwrite_key, $overwrite_value) {
- $params[$overwrite_key] = $overwrite_value;
- return "?" . http_build_query($params);
- }
- }
- //function that actually overwrites the query parameters
- add_action('woocommerce_get_catalog_ordering_args', 'avia_woocommerce_overwrite_catalog_ordering', 20);
- if (!function_exists('avia_woocommerce_overwrite_catalog_ordering')) {
- function avia_woocommerce_overwrite_catalog_ordering($args) {
- global $tw_woocommerce;
- if (!tw_option('woo_sorting'))
- return $args;
- //check the folllowing get parameters and session vars. if they are set overwrite the defaults
- $check = array('product_order', 'product_count', 'product_sort');
- if (empty($tw_woocommerce))
- $tw_woocommerce = array();
- foreach ($check as $key) {
- if (isset($_GET[$key]))
- $_SESSION['tw_woocommerce'][$key] = esc_attr($_GET[$key]);
- if (isset($_SESSION['tw_woocommerce'][$key]))
- $tw_woocommerce[$key] = $_SESSION['tw_woocommerce'][$key];
- }
- // is user wants to use new product order remove the old sorting parameter
- if (isset($_GET['product_order']) && !isset($_GET['product_sort']) && isset($_SESSION['tw_woocommerce']['product_sort'])) {
- unset($_SESSION['tw_woocommerce']['product_sort'], $tw_woocommerce['product_sort']);
- }
- extract($tw_woocommerce);
- // set the product order
- if (!empty($product_order)) {
- switch ($product_order) {
- case 'date' : $orderby = 'date';
- $order = 'desc';
- $meta_key = '';
- break;
- case 'price' : $orderby = 'meta_value_num';
- $order = 'asc';
- $meta_key = '_price';
- break;
- case 'popularity' : $orderby = 'meta_value_num';
- $order = 'desc';
- $meta_key = 'total_sales';
- break;
- case 'title' : $orderby = 'title';
- $order = 'asc';
- $meta_key = '';
- break;
- case 'default':
- default : $orderby = 'menu_order title';
- $order = 'asc';
- $meta_key = '';
- break;
- }
- }
- // set the product count
- if (!empty($product_count) && is_numeric($product_count)) {
- $tw_woocommerce['products_per_page'] = (int) $product_count;
- }
- //set the product sorting
- if (!empty($product_sort)) {
- switch ($product_sort) {
- case 'desc' : $order = 'desc';
- break;
- case 'asc' : $order = 'asc';
- break;
- default : $order = 'asc';
- break;
- }
- }
- if (isset($orderby))
- $args['orderby'] = $orderby;
- if (isset($order))
- $args['order'] = $order;
- if (!empty($meta_key)) {
- $args['meta_key'] = $meta_key;
- }
- $tw_woocommerce['product_sort'] = $args['order'];
- return $args;
- }
- }
- /**
- * WooCommerce Extra Feature
- * --------------------------
- *
- * Change number of related products on product page
- * Set your own value for 'posts_per_page'
- *
- */
- if (!function_exists('woo_related_products_limit')) {
- function woo_related_products_limit() {
- global $product;
- $args['posts_per_page'] = 6;
- return $args;
- }
- }
- add_filter('woocommerce_output_related_products_args', 'jk_related_products_args');
- if (!function_exists('jk_related_products_args')) {
- function jk_related_products_args($args) {
- $args['posts_per_page'] = 3; // 4 related products
- $args['columns'] = 3; // arranged in 2 columns
- return $args;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement