/** * 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(); }
/** * 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'); }
function jigoshop_product_add_to_cart($atts) { if (empty($atts)) { return; } $atts = shortcode_atts(array('class' => 'product', 'id' => false, 'sku' => false, 'price' => 'yes'), $atts); global $wpdb; if ($atts['id']) { $product_meta = get_post($atts['id']); } elseif ($atts['sku']) { $product_id = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key='sku' AND meta_value=%s LIMIT 1", $atts['sku'])); $product_meta = get_post($product_id); } else { return; } if ($product_meta->post_type !== 'product') { return; } $_product = new jigoshop_product($product_meta->ID); if (!$_product->is_visible()) { return; } ob_start(); ?> <p class="<?php echo esc_attr($atts['class']); ?> "> <?php if ($atts['price'] != 'no') { echo $_product->get_price_html(); } ?> <?php jigoshop_template_loop_add_to_cart($product_meta, $_product); ?> </p><?php return ob_get_clean(); }
function jigoshop_custom_product_columns($column) { global $post; $jigoshop_options = Jigoshop_Base::get_options(); $product = new jigoshop_product($post->ID); switch ($column) { case "thumb": if ('trash' != $post->post_status) { echo '<a class="row-title" href="' . get_edit_post_link($post->ID) . '">'; echo jigoshop_get_product_thumbnail('admin_product_list'); echo '</a>'; } else { echo jigoshop_get_product_thumbnail('admin_product_list'); } break; case "price": echo $product->get_price_html(); break; case "featured": $url = wp_nonce_url(admin_url('admin-ajax.php?action=jigoshop-feature-product&product_id=' . $post->ID)); echo '<a href="' . esc_url($url) . '" title="' . __('Change', 'jigoshop') . '">'; if ($product->is_featured()) { echo '<a href="' . esc_url($url) . '"><img src="' . jigoshop::assets_url() . '/assets/images/head_featured_desc.png" alt="yes" />'; } else { echo '<img src="' . jigoshop::assets_url() . '/assets/images/head_featured.png" alt="no" />'; } echo '</a>'; break; case "stock": if (!$product->is_type('grouped') && $product->is_in_stock()) { if ($product->managing_stock()) { if ($product->is_type('variable') && $product->stock > 0) { echo $product->stock . ' ' . __('In Stock', 'jigoshop'); } else { if ($product->is_type('variable')) { $stock_total = 0; foreach ($product->get_children() as $child_ID) { $child = $product->get_child($child_ID); $stock_total += (int) $child->stock; } echo $stock_total . ' ' . __('In Stock', 'jigoshop'); } else { echo $product->stock . ' ' . __('In Stock', 'jigoshop'); } } } else { echo __('In Stock', 'jigoshop'); } } elseif ($product->is_type('grouped')) { echo __('Parent (no stock)', 'jigoshop'); } else { echo '<strong class="attention">' . __('Out of Stock', 'jigoshop') . '</strong>'; } break; case "product-type": echo __(ucwords($product->product_type), 'jigoshop'); echo '<br/>'; if ($jigoshop_options->get('jigoshop_enable_sku', true) == 'yes' && ($sku = get_post_meta($post->ID, 'sku', true))) { echo $sku; } else { echo $post->ID; } break; case "product-date": if ('0000-00-00 00:00:00' == $post->post_date) { $t_time = $h_time = __('Unpublished', 'jigoshop'); $time_diff = 0; } else { $t_time = get_the_time(__('Y/m/d g:i:s A', 'jigoshop')); $m_time = $post->post_date; $time = get_post_time('G', true, $post); $time_diff = time() - $time; if ($time_diff > 0 && $time_diff < 24 * 60 * 60) { $h_time = sprintf(__('%s ago', 'jigoshop'), human_time_diff($time)); } else { $h_time = mysql2date(__('Y/m/d', 'jigoshop'), $m_time); } } echo '<abbr title="' . esc_attr($t_time) . '">' . apply_filters('post_date_column_time', $h_time, $post) . '</abbr><br />'; if ('publish' == $post->post_status) { _e('Published', 'jigoshop'); } elseif ('future' == $post->post_status) { if ($time_diff > 0) { echo '<strong class="attention">' . __('Missed schedule', 'jigoshop') . '</strong>'; } else { _e('Scheduled', 'jigoshop'); } } else { _e('Draft', 'jigoshop'); } if ($product->visibility) { echo $product->visibility != 'visible' ? '<br /><strong class="attention">' . ucfirst($product->visibility) . '</strong>' : ''; } break; case "product-visibility": if ($product->visibility) { echo $product->visibility == 'Hidden' ? '<strong class="attention">' . ucfirst($product->visibility) . '</strong>' : ucfirst($product->visibility); } break; } }
/** * 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; 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><div class="inner">'; // Print the product image & title with a link to the permalink echo '<figure class="featured-thumbnail"><a href="' . get_permalink() . '" title="' . esc_attr(get_the_title()) . '" class="thumb">'; echo '<span class="stroke"></span><span class="image-wrapper">'; $thumb = get_post_thumbnail_id(); $img_url = wp_get_attachment_url($thumb, 'full'); //get img URL $img = aq_resize($img_url, 356, 222, true); $trex = substr(get_the_excerpt(), 0, 120); echo '<img src="' . $img . '" alt="">'; echo '</span>'; echo '</a></figure>'; echo '<div class="js_widget_product_title"><a href="' . get_permalink() . '">' . get_the_title() . '</a></div>'; echo '<span class="js_widget_product_excerpt">' . $trex . '</span>'; // Print the price with html wrappers echo '<span class="js_widget_product_price">' . $_product->get_price_html() . '</span>'; echo '<a href="' . get_permalink() . '" class="js_widget_product_link button">Details</a>'; 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_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(); }
function getWProductItems($cat_id) { $html = ''; // get slug by ID $term = get_term_by('id', $cat_id, 'product_cat'); if ($term) { $args = array('posts_per_page' => 6, 'product_cat' => $term->slug, 'post_type' => 'product'); $posts = get_posts($args); ob_start(); global $post; $tmp_post = $post; $options = get_option('mashmenu_options'); $sizes = $options['thumbnail_size']; $width = 200; $height = 200; if ($sizes != '') { $sizes = explode('x', $sizes); if (count($sizes) == 2) { $width = intval($sizes[0]); $height = intval($sizes[1]); if ($width == 0) { $width = 200; } if ($height == 0) { $height = 200; } } } foreach ($posts as $post) { setup_postdata($post); //$product = WC_Product($post->ID); if (class_exists('WC_Product')) { // WooCommerce Installed global $product; } else { if (class_exists('jigoshop_product')) { $product = new jigoshop_product($post->ID); // JigoShop } } ?> <div class="content-item"> <?php $options['image_link'] = 'on'; if ($options['image_link'] == 'on') { ?> <a href="<?php the_permalink(); ?> " title="<?php the_title(); ?> "> <?php the_post_thumbnail(array($width, $height)); ?> </a> <?php } else { ?> <?php the_post_thumbnail(array($width, $height)); ?> <?php } ?> <h3 class="title"><a href="<?php the_permalink(); ?> " title="<?php the_title(); ?> "><?php if ($options['show_price'] == 'left' && ($price_html = $product->get_price_html())) { echo $price_html; } ?> <?php the_title(); ?> <?php if ((!isset($options['show_price']) || $options['show_price'] == '') && ($price_html = $product->get_price_html())) { echo $price_html; } ?> </a></h3> </div> <?php } $html = ob_get_contents(); ob_end_clean(); $post = $temp_post; } return $html; }
/** * 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'); }