/** * Add Menu Cart to menu * * @return menu items including cart */ public function submenu_items() { $get_cart = jigoshop_cart::get_cart(); $submenu_items = ''; //see jigoshop/widgets/cart.php if (count($get_cart) > 0) { foreach ($get_cart as $cart_item_key => $values) { $_product = $values['data']; if ($_product->exists() && $values['quantity'] > 0) { $item_thumbnail = has_post_thumbnail($_product->id) ? get_the_post_thumbnail($_product->id, 'shop_tiny') : jigoshop_get_image_placeholder('shop_tiny'); $item_name = $_product->get_title(); // Not used: Displays variations and cart item meta $item_meta = jigoshop_cart::get_item_data($values); $item_quantity = esc_attr($values['quantity']); $item_price = $_product->get_price_html(); // Item permalink $item_permalink = esc_attr(get_permalink($_product->id)); $submenu_items[] = array('item_thumbnail' => $item_thumbnail, 'item_name' => $item_name, 'item_quantity' => $item_quantity, 'item_price' => $item_price, 'item_permalink' => $item_permalink); } } } else { $submenu_items = ''; } return $submenu_items; }
/** * Widget * Display the widget in the sidebar * Save output to the cache if empty * * @param array sidebar arguments * @param array instance */ public function widget($args, $instance) { // Hide widget if page is the cart or checkout if (is_cart() || is_checkout()) { return false; } extract($args); // Set the widget title $title = apply_filters('widget_title', $instance['title'] ? $instance['title'] : __('Cart', 'jigoshop'), $instance, $this->id_base); // Print the widget wrapper & title echo $before_widget; if ($title) { echo $before_title . $title . $after_title; } // Get the contents of the cart $cart_contents = jigoshop_cart::$cart_contents; // If there are items in the cart print out a list of products if (!empty($cart_contents)) { // Open the list echo '<ul class="cart_list">'; foreach ($cart_contents as $key => $value) { // Get product instance $_product = $value['data']; if ($_product->exists() && $value['quantity'] > 0) { echo '<li>'; // Print the product image & title with a link to the permalink echo '<a href="' . esc_attr(get_permalink($_product->id)) . '" title="' . esc_attr($_product->get_title()) . '">'; // Print the product thumbnail image if exists else display placeholder echo has_post_thumbnail($_product->id) ? get_the_post_thumbnail($_product->id, 'shop_tiny') : jigoshop_get_image_placeholder('shop_tiny'); // Print the product title echo '<span class="js_widget_product_title">' . $_product->get_title() . '</span>'; echo '</a>'; // Displays variations and cart item meta echo jigoshop_cart::get_item_data($value); // Print the quantity & price per product echo '<span class="js_widget_product_price">' . $value['quantity'] . ' × ' . $_product->get_price_html() . '</span>'; echo '</li>'; } } echo '</ul>'; // Close the list // Print the cart total echo '<p class="total"><strong>'; echo __('Subtotal', 'jigoshop'); echo ':</strong> ' . jigoshop_price($this->total_cart_items()); echo '</p>'; do_action('jigoshop_widget_cart_before_buttons'); // Print view cart & checkout buttons $view_cart_button_label = isset($instance['view_cart_button']) ? $instance['view_cart_button'] : __('View Cart →', 'jigoshop'); $checkout_button_label = isset($instance['checkout_button']) ? $instance['checkout_button'] : __('Checkout →', 'jigoshop'); echo '<p class="buttons">'; echo '<a href="' . esc_attr(jigoshop_cart::get_cart_url()) . '" class="button">' . __($view_cart_button_label, 'jigoshop') . '</a>'; echo '<a href="' . esc_attr(jigoshop_cart::get_checkout_url()) . '" class="button checkout">' . __($checkout_button_label, 'jigoshop') . '</a>'; echo '</p>'; } else { echo '<span class="empty">' . __('No products in the cart.', 'jigoshop') . '</span>'; } // Print closing widget wrapper echo $after_widget; }
/** * Widget * Display the widget in the sidebar * Save output to the cache if empty * * @param array sidebar arguments * @param array instance */ public function widget($args, $instance) { // Get the best selling products from the transient $cache = get_transient('jigoshop_widget_cache'); // If cached get from the cache if (isset($cache[$args['widget_id']])) { echo $cache[$args['widget_id']]; return false; } // Start buffering ob_start(); extract($args); // Set the widget title $title = apply_filters('widget_title', $instance['title'] ? $instance['title'] : __('Best Sellers', 'jigoshop'), $instance, $this->id_base); // Set number of products to fetch if (!($number = absint($instance['number']))) { $number = 5; } // Set up query $query_args = array('posts_per_page' => $number, 'post_type' => 'product', 'post_status' => 'publish', 'meta_key' => 'quantity_sold', 'orderby' => 'meta_value_num+0', 'order' => 'desc', 'nopaging' => false, 'meta_query' => array(array('key' => 'visibility', 'value' => array('catalog', 'visible'), 'compare' => 'IN'))); // Run the query $q = new WP_Query($query_args); // If there are products if ($q->have_posts()) { // Print the widget wrapper & title echo $before_widget; if ($title) { echo $before_title . $title . $after_title; } // Open the list echo '<ul class="product_list_widget">'; // Print out each product while ($q->have_posts()) { $q->the_post(); // Get a new jigoshop_product instance $_product = new jigoshop_product(get_the_ID()); echo '<li>'; // Print the product image & title with a link to the permalink echo '<a href="' . esc_attr(get_permalink()) . '" title="' . esc_attr(get_the_title()) . '">'; // Print the product image echo has_post_thumbnail() ? the_post_thumbnail('shop_tiny') : jigoshop_get_image_placeholder('shop_tiny'); echo '<span class="js_widget_product_title">' . get_the_title() . '</span>'; echo '</a>'; // Print the price with html wrappers echo '<span class="js_widget_product_price">' . $_product->get_price_html() . '</span>'; echo '</li>'; } echo '</ul>'; // Close the list // Print closing widget wrapper echo $after_widget; // Reset the global $the_post as this query will have stomped on it wp_reset_postdata(); } // Flush output buffer and save to transient cache $cache[$args['widget_id']] = ob_get_flush(); set_transient('jigoshop_widget_cache', $cache, 3600 * 3); // 3 hours ahead }
/** * Widget * Display the widget in the sidebar * Save output to the cache if empty * * @param array sidebar arguments * @param array instance */ public function widget($args, $instance) { // Start buffering ob_start(); extract($args); // Set the widget title $title = apply_filters('widget_title', $instance['title'] ? $instance['title'] : __('Random Products', 'jigoshop'), $instance, $this->id_base); // Set number of products to fetch if (!($number = absint($instance['number']))) { $number = 5; } // Set up query $query_args = array('posts_per_page' => $number, 'post_type' => 'product', 'post_status' => 'publish', 'orderby' => 'rand', 'meta_query' => array(array('key' => 'visibility', 'value' => array('catalog', 'visible'), 'compare' => 'IN'))); // Run the query $q = new WP_Query($query_args); // If there are products if ($q->have_posts()) { // Print the widget wrapper & title echo $before_widget; if ($title) { echo $before_title . $title . $after_title; } // Open the list echo '<ul class="product_list_widget">'; // Print out each product while ($q->have_posts()) { $q->the_post(); // Get new jigoshop_product instance $_product = new jigoshop_product(get_the_ID()); echo '<li>'; // Print the product image & title with a link to the permalink echo '<a href="' . get_permalink() . '" title="' . esc_attr(get_the_title()) . '">'; echo has_post_thumbnail() ? the_post_thumbnail('shop_tiny') : jigoshop_get_image_placeholder('shop_tiny'); echo '<span class="js_widget_product_title">' . get_the_title() . '</span>'; echo '</a>'; // Print the price with html wrappers echo '<span class="js_widget_product_price">' . $_product->get_price_html() . '</span>'; echo '</li>'; } echo '</ul>'; // Close the list // Print closing widget wrapper echo $after_widget; // Reset the global $the_post as this query will have stomped on it wp_reset_postdata(); } ob_get_flush(); }
function colabs_jigoshop_show_product_images() { global $_product, $post; echo '<div class="images gallery-item">'; do_action('jigoshop_before_single_product_summary_thumbnails', $post, $_product); $thumb_id = 0; if (has_post_thumbnail()) { $thumb_id = get_post_thumbnail_id(); // since there are now user settings for sizes, shouldn't need filters -JAP- //$large_thumbnail_size = apply_filters('single_product_large_thumbnail_size', 'shop_large'); $large_thumbnail_size = jigoshop_get_image_size('shop_large'); $image_classes = apply_filters('jigoshop_product_image_classes', array(), $_product); array_unshift($image_classes, 'zoom'); $image_classes = implode(' ', $image_classes); echo '<a href="' . wp_get_attachment_url($thumb_id) . '" class="' . $image_classes . '" rel="thumbnails">'; the_post_thumbnail($large_thumbnail_size); echo '</a>'; } else { echo jigoshop_get_image_placeholder('shop_large'); } do_action('jigoshop_product_thumbnails'); echo '</div>'; }
/** * Widget * Display the widget in the sidebar * Save output to the cache if empty * * @param array sidebar arguments * @param array instance */ public function widget($args, $instance) { // Get the most recently viewed products from the cache $cache = wp_cache_get('widget_recently_viewed_products', 'widget'); // If no entry exists use array if (!is_array($cache)) { $cache = array(); } // If cached get from the cache if (isset($cache[$args['widget_id']])) { echo $cache[$args['widget_id']]; return false; } // Check if session contains recently viewed products if (empty(jigoshop_session::instance()->recently_viewed_products)) { return false; } // Start buffering the output ob_start(); extract($args); // Set the widget title $title = apply_filters('widget_title', $instance['title'] ? $instance['title'] : __('Recently Viewed Products', 'jigoshop'), $instance, $this->id_base); // Set number of products to fetch if (!($number = absint($instance['number']))) { $number = 5; } // Set up query $query_args = array('posts_per_page' => $number, 'post_type' => 'product', 'post_status' => 'publish', 'nopaging' => true, 'post__in' => jigoshop_session::instance()->recently_viewed_products, 'orderby' => 'date', 'meta_query' => array(array('key' => 'visibility', 'value' => array('catalog', 'visible'), 'compare' => 'IN'))); // Run the query $q = new WP_Query($query_args); if ($q->have_posts()) { // Print the widget wrapper & title echo $before_widget; if ($title) { echo $before_title . $title . $after_title; } // Open the list echo '<ul class="product_list_widget recently_viewed_products">'; // Print out each produt while ($q->have_posts()) { $q->the_post(); // Get new jigoshop_product instance $_product = new jigoshop_product(get_the_ID()); echo '<li>'; //print the product title with a permalink echo '<a href="' . get_permalink() . '" title="' . esc_attr(get_the_title()) . '">'; // Print the product image echo has_post_thumbnail() ? the_post_thumbnail('shop_tiny') : jigoshop_get_image_placeholder('shop_tiny'); echo '<span class="js_widget_product_title">' . get_the_title() . '</span>'; echo '</a>'; // Print the price with wrappers ..yum! echo '<span class="js_widget_product_price">' . $_product->get_price_html() . '</span>'; echo '</li>'; } echo '</ul>'; // Close the list // Print closing widget wrapper echo $after_widget; // Reset the global $the_post as this query will have stomped on it wp_reset_postdata(); } // Flush output buffer and save to cache $cache[$args['widget_id']] = ob_get_flush(); wp_cache_set('widget_recent_products', $cache, 'widget'); }
/** * Widget * * Display the widget in the sidebar * Save output to the cache if empty * * @param array sidebar arguments * @param array instance */ public function widget($args, $instance) { // Get the most recent products from the cache $cache = wp_cache_get('widget_recent_reviews', 'widget'); // If no entry exists use array if (!is_array($cache)) { $cache = array(); } // If cached get from the cache if (isset($cache[$args['widget_id']])) { echo $cache[$args['widget_id']]; return false; } // Start buffering ob_start(); extract($args); // Set the widget title $title = apply_filters('widget_title', $instance['title'] ? $instance['title'] : __('Recent Reviews', 'jigoshop'), $instance, $this->id_base); // Set number of products to fetch if (!($number = absint($instance['number']))) { $number = 5; } // Modify get_comments query to only include products which are visible add_filter('comments_clauses', array(&$this, 'where_product_is_visible')); // Get the latest reviews $comments = get_comments(array('number' => $number, 'status' => 'approve', 'post_status' => 'publish', 'post_type' => 'product')); // If there are products if ($comments) { // Print the widget wrapper & title echo $before_widget; echo $before_title . $title . $after_title; // Open the list echo '<ul class="product_list_widget">'; // Print out each product foreach ($comments as $comment) { // Get new jigoshop_product instance $_product = new jigoshop_product($comment->comment_post_ID); // Skip products that are invisible if ($_product->visibility == 'hidden') { continue; } // TODO: Refactor this // Apply star size $star_size = apply_filters('jigoshop_star_rating_size_recent_reviews', 16); $rating = get_comment_meta($comment->comment_ID, 'rating', true); echo '<li>'; // Print the product image & title with a link to the permalink echo '<a href="' . esc_url(get_comment_link($comment->comment_ID)) . '">'; // Print the product image echo has_post_thumbnail($_product->id) ? get_the_post_thumbnail($_product->id, 'shop_tiny') : jigoshop_get_image_placeholder('shop_tiny'); echo '<span class="js_widget_product_title">' . $_product->get_title() . '</span>'; echo '</a>'; // Print the star rating echo "<div class='star-rating' title='{$rating}'>\n\t\t\t\t\t\t<span style='width:" . $rating * $star_size . "px;'>{$rating} " . __('out of 5', 'jigoshop') . "</span>\n\t\t\t\t\t</div>"; // Print the author printf(_x('by %1$s', 'author', 'jigoshop'), get_comment_author()); echo '</li>'; } echo '</ul>'; // Close the list // Print closing widget wrapper echo $after_widget; // Remove the filter on comments to stop other queries from being manipulated remove_filter('comments_clauses', array(&$this, 'where_product_is_visible')); } // Flush output buffer and save to cache $cache[$args['widget_id']] = ob_get_flush(); wp_cache_set('widget_recent_reviews', $cache, 'widget'); }
/** * Widget * Display the widget in the sidebar * Save output to the cache if empty * * @param array sidebar arguments * @param array instance */ public function widget($args, $instance) { // Get the most recent products from the cache $cache = wp_cache_get('widget_recent_products', 'widget'); // If no entry exists use array if (!is_array($cache)) { $cache = array(); } // If cached get from the cache if (isset($cache[$args['widget_id']])) { echo $cache[$args['widget_id']]; return false; } // Start buffering ob_start(); extract($args); // Set the widget title $title = apply_filters('widget_title', $instance['title'] ? $instance['title'] : __('Special Offers', 'jigoshop'), $instance, $this->id_base); // Set number of products to fetch if (!($number = absint($instance['number']))) { $number = 5; } // Set up query $time = current_time('timestamp'); $query_args = array('posts_per_page' => -1, 'post_type' => 'product', 'post_status' => 'publish', 'orderby' => 'rand', 'meta_query' => array(array('key' => 'visibility', 'value' => array('catalog', 'visible'), 'compare' => 'IN'), array('key' => 'sale_price_dates_from', 'value' => $time, 'compare' => '<='), array('key' => 'sale_price_dates_to', 'value' => $time, 'compare' => '>='))); $q = new WP_Query($query_args); // If there are products if ($q->have_posts()) { // Print the widget wrapper & title echo $before_widget; if ($title) { echo $before_title . $title . $after_title; } // Open the list echo '<ul class="product_list_widget">'; // Print out each product for ($i = 0; $q->have_posts() && $i < $number;) { $q->the_post(); // Get new jigoshop_product instance $_product = new jigoshop_product(get_the_ID()); // Skip if not on sale if (!$_product->is_on_sale()) { continue; } else { $i++; } echo '<li>'; // Print the product image & title with a link to the permalink echo '<a href="' . get_permalink() . '" title="' . esc_attr(get_the_title()) . '">'; // Print the product image echo has_post_thumbnail() ? the_post_thumbnail('shop_tiny') : jigoshop_get_image_placeholder('shop_tiny'); echo '<span class="js_widget_product_title">' . get_the_title() . '</span>'; echo '</a>'; // Print the price with html wrappers echo '<span class="js_widget_product_price">' . $_product->get_price_html() . '</span>'; echo '</li>'; } echo '</ul>'; // Close the list // Print closing widget wrapper echo $after_widget; // Reset the global $the_post as this query will have stomped on it wp_reset_postdata(); } ob_get_flush(); }
/** * Get the main product image or parents image * * @param string $size * @return string HTML */ public function get_image($size = 'shop_thumbnail') { // Get the image size $size = jigoshop_get_image_size($size); // If product has an image if (has_post_thumbnail($this->ID)) { return get_the_post_thumbnail($this->ID, $size); } // If product has a parent and that has an image display that if (($parent_ID = wp_get_post_parent_id($this->ID)) && has_post_thumbnail($parent_ID)) { return get_the_post_thumbnail($this->ID, $size); } // Otherwise just return a placeholder return jigoshop_get_image_placeholder($size); }
function jigoshop_get_product_thumbnail($size = 'shop_small') { global $post; if (has_post_thumbnail()) { return get_the_post_thumbnail($post->ID, $size); } else { return jigoshop_get_image_placeholder($size); } }
function wallpress_jigo_minicart() { ?> <div id="jigo_minicart"> <a href="#" class="minicart"><i class="fa fa-shopping-cart"></i></a> <div class="cartlist"> <div class="cat-inner"> <?php $cart_contents = class_exists('jigoshop_cart') ? jigoshop_cart::$cart_contents : ''; ?> <?php if (!empty($cart_contents)) { ?> <ul class="cart_list"> <?php foreach ($cart_contents as $key => $value) { ?> <?php $_product = $value['data']; ?> <?php if ($_product->exists() && $value['quantity'] > 0) { ?> <li class="clearfix"> <a href="<?php echo esc_attr(get_permalink($_product->id)); ?> " title="<?php echo esc_attr($_product->get_title()); ?> "> <?php echo has_post_thumbnail($_product->id) ? get_the_post_thumbnail($_product->id, 'shop_tiny') : jigoshop_get_image_placeholder('shop_tiny'); ?> <h4 class="js_widget_product_title"><?php echo $_product->get_title(); ?> </h4> </a> <div class="js_widget_product_price"> <span class="price"><?php echo $_product->get_price_html(); ?> </span> <?php _e(' · QTY', 'dw-wallpress'); echo $value['quantity']; ?> </div> </li> <?php } ?> <?php } ?> </ul> <p class="total"> <strong><?php _e(get_option('jigoshop_prices_include_tax') == 'yes' ? 'Total' : 'Subtotal', 'dw-wallpress'); ?> </strong> <span class="totalNum"><?php echo jigoshop_cart::get_cart_total(); ?> </span> </p> <?php do_action('jigoshop_widget_cart_before_buttons'); ?> <p class="buttons clearfix"> <a href="<?php echo esc_attr(jigoshop_cart::get_cart_url()); ?> " class="button"> <?php _e('View Cart →', 'dw-wallpress'); ?> </a> <a href="<?php echo esc_attr(jigoshop_cart::get_checkout_url()); ?> " class="button checkout"> <?php _e('Checkout →', 'dw-wallpress'); ?> </a> </p> <?php } else { ?> <span class="empty"><?php _e('No products in the cart.', 'dw-wallpress'); ?> </span> <?php } ?> </div> </div> </div> <?php }
/** * Widget * Display the widget in the sidebar * Save output to the cache if empty * * @param array sidebar arguments * @param array instance */ public function widget($args, $instance) { // Get the most recent products from the cache $cache = wp_cache_get('widget_recent_products', 'widget'); // If no entry exists use array if (!is_array($cache)) { $cache = array(); } // If cached get from the cache if (isset($cache[$args['widget_id']])) { echo $cache[$args['widget_id']]; return false; } // Start buffering ob_start(); extract($args); // Set the widget title $title = apply_filters('widget_title', $instance['title'] ? $instance['title'] : __('Top Rated Products', 'jigoshop'), $instance, $this->id_base); // Set number of products to fetch if (!($number = absint($instance['number']))) { $number = 5; } // Set up query // Filter the $wpdb query add_filter('posts_clauses', array($this, 'order_by_rating')); // TODO: Only display products that are in stock $query_args = array('posts_per_page' => $number, 'post_type' => 'product', 'post_status' => 'publish', 'meta_query' => array(array('key' => 'visibility', 'value' => array('catalog', 'visible'), 'compare' => 'IN'))); // Run the query $q = new WP_Query($query_args); // If there are products if ($q->have_posts()) { // Print the widget wrapper & title echo $before_widget; if ($title) { echo $before_title . $title . $after_title; } // Open the list echo '<ul class="product_list_widget">'; // Print out each product while ($q->have_posts()) { $q->the_post(); $_product = new jigoshop_product($q->post->ID); echo '<li>'; // Print the title with a link to the permalink echo '<a href="' . esc_url(get_permalink()) . '" title="' . esc_attr(get_the_title()) . '">'; // Print the product image echo has_post_thumbnail() ? the_post_thumbnail('shop_tiny') : jigoshop_get_image_placeholder('shop_tiny'); echo '<span class="js_widget_product_title">' . get_the_title() . '</span>'; echo '</a>'; // Print the average rating with html wrappers echo $_product->get_rating_html('sidebar'); // Print the price with html wrappers echo '<span class="js_widget_product_price">' . $_product->get_price_html() . '</span>'; echo '</li>'; } echo '</ul>'; // Close the list // Print closing widget wrapper echo $after_widget; // Reset the global $the_post as this query will have stomped on it wp_reset_postdata(); remove_filter('posts_clauses', array($this, 'order_by_rating')); } // Flush output buffer and save to cache $cache[$args['widget_id']] = ob_get_flush(); wp_cache_set('widget_recent_products', $cache, 'widget'); }
/** * Widget * Display the widget in the sidebar * Save output to the cache if empty * * @param array sidebar arguments * @param array instance */ function widget($args, $instance) { // Get the most recent products from the cache $cache = wp_cache_get('widget_recent_products', 'widget'); // If no entry exists use array if (!is_array($cache)) { $cache = array(); } // If cached get from the cache if (isset($cache[$args['widget_id']])) { echo $cache[$args['widget_id']]; return false; } // Start buffering ob_start(); extract($args); // Set the widget title $title = $instance['title'] ? $instance['title'] : __('New Products', 'jigoshop'); $title = apply_filters('widget_title', $title, $instance, $this->id_base); // Set number of products to fetch if (!($number = $instance['number'])) { $number = 10; } $number = apply_filters('jigoshop_widget_recent_default_number', $number, $instance, $this->id_base); // Set up query $query_args = array('posts_per_page' => $number, 'post_type' => 'product', 'post_status' => 'publish', 'orderby' => 'date', 'order' => 'desc', 'meta_query' => array(array('key' => 'visibility', 'value' => array('catalog', 'visible'), 'compare' => 'IN'))); // Show variations of products? TODO: fix this -JAP- /* if( ! $instance['show_variations']) { $query_args['meta_query'] = array( array( 'key' => 'visibility', 'value' => array('catalog', 'visible'), 'compare' => 'IN', ), ); $query_args['parent'] = false; } */ // Run the query $q = new WP_Query($query_args); // If there are products if ($q->have_posts()) { // Print the widget wrapper & title echo $before_widget; if ($title) { echo $before_title . $title . $after_title; } // Open the list echo '<ul class="product_list_widget">'; // Print out each product while ($q->have_posts()) { $q->the_post(); // Get new jigoshop_product instance $_product = new jigoshop_product(get_the_ID()); echo '<li>'; // Print the product image & title with a link to the permalink echo '<a href="' . get_permalink() . '" title="' . esc_attr(get_the_title()) . '">'; echo has_post_thumbnail() ? the_post_thumbnail('shop_tiny') : jigoshop_get_image_placeholder('shop_tiny'); echo '<span class="js_widget_product_title">' . get_the_title() . '</span>'; echo '</a>'; // Print the price with html wrappers echo '<span class="js_widget_product_price">' . $_product->get_price_html() . '</span>'; echo '</li>'; } echo '</ul>'; // Close the list // Print closing widget wrapper echo $after_widget; // Reset the global $the_post as this query will have stomped on it wp_reset_postdata(); } // Flush output buffer and save to cache $cache[$args['widget_id']] = ob_get_flush(); wp_cache_set('widget_recent_products', $cache, 'widget'); }