本文整理汇总了PHP中woocommerce_product_loop_start函数的典型用法代码示例。如果您正苦于以下问题:PHP woocommerce_product_loop_start函数的具体用法?PHP woocommerce_product_loop_start怎么用?PHP woocommerce_product_loop_start使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了woocommerce_product_loop_start函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: output_featured_products
function output_featured_products()
{
$args = array('post_type' => 'product', 'posts_per_page' => 3, 'product_tag' => 'featured', 'orderby' => 'rand');
$products = new WP_Query($args);
if ($products->have_posts()) {
?>
<div class="related products">
<h2><?php
_e('Featured Products', 'woocommerce');
?>
</h2>
<?php
woocommerce_product_loop_start();
?>
<?php
while ($products->have_posts()) {
$products->the_post();
?>
<?php
wc_get_template_part('content', 'product');
?>
<?php
}
// end of the loop.
?>
<?php
woocommerce_product_loop_end();
?>
</div>
<?php
}
wp_reset_postdata();
}
示例2: content
protected function content($atts, $content = null)
{
$atts = shortcode_atts(array('product_type' => 'classic', 'product_effect' => '', 'desktop' => 4, 'per_page' => 10, 'orderby' => 'date', 'meta_key' => '', 'order' => 'DESC', 'source' => 'all', 'categories' => '', 'products' => '', 'operator' => 'IN', 'css_animation' => '', 'el_class' => '', 'css' => ''), $atts);
extract($atts);
$elementClass = array('base' => apply_filters(VC_SHORTCODE_CUSTOM_CSS_FILTER_TAG, 'cruxstore-products', $this->settings['base'], $atts), 'extra' => $this->getExtraClass($el_class), 'css_animation' => $this->getCSSAnimation($css_animation), 'shortcode_custom' => vc_shortcode_custom_css_class($css, ' '), 'product_stype' => 'cruxstore-products-' . $product_type, 'woocommerce' => 'woocommerce columns-' . $desktop);
$meta_query = WC()->query->get_meta_query();
if ($source == 'best-sellers') {
$meta_key = 'total_sales';
$orderby = 'meta_value_num';
}
$args = array('post_type' => 'product', 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'posts_per_page' => $per_page, 'meta_query' => $meta_query, 'order' => $order, 'orderby' => $orderby, 'meta_key' => $meta_key);
if ($source == 'onsale') {
$product_ids_on_sale = wc_get_product_ids_on_sale();
$args['post__in'] = array_merge(array(0), $product_ids_on_sale);
} elseif ($source == 'featured') {
$args['meta_query'][] = array('key' => '_featured', 'value' => 'yes');
} elseif ($source == 'top-rated') {
add_filter('posts_clauses', array(__CLASS__, 'order_by_rating_post_clauses'));
} elseif ($source == 'categories') {
if (!empty($categories)) {
$args['tax_query'] = array(array('taxonomy' => 'product_cat', 'terms' => array_map('sanitize_title', explode(',', $categories)), 'field' => 'slug', 'operator' => $operator));
}
} elseif ($source == 'products') {
if (!empty($atts['products'])) {
$args['post__in'] = array_map('trim', explode(',', $atts['products']));
}
}
$output = '';
ob_start();
global $woocommerce_loop;
$products = new WP_Query(apply_filters('woocommerce_shortcode_products_query', $args, $atts));
if ($product_type != 'classic') {
$product_effect = '';
}
$woocommerce_loop['columns'] = $desktop;
$woocommerce_loop['type'] = $product_type;
$woocommerce_loop['effect'] = $product_effect;
if ($products->have_posts()) {
woocommerce_product_loop_start();
if ($product_type == 'masonry') {
echo '<div class="clearfix product col-sm-3 grid-sizer"></div>';
}
while ($products->have_posts()) {
$products->the_post();
wc_get_template_part('content', 'product');
}
// end of the loop.
woocommerce_product_loop_end();
}
wp_reset_postdata();
if ($source == 'top-rated') {
remove_filter('posts_clauses', array(__CLASS__, 'order_by_rating_post_clauses'));
}
$output .= ob_get_clean();
$elementClass = preg_replace(array('/\\s+/', '/^\\s|\\s$/'), array(' ', ''), implode(' ', $elementClass));
return '<div class="' . esc_attr($elementClass) . '">' . $output . '</div>';
}
示例3: content
protected function content($atts, $content = null)
{
$atts = shortcode_atts(array('per_page' => 10, 'orderby' => 'date', 'meta_key' => '', 'order' => 'DESC', 'source' => '', 'categories' => '', 'products' => '', 'operator' => 'IN', 'layout' => 'normal', 'autoheight' => true, 'autoplay' => false, 'mousedrag' => true, 'autoplayspeed' => 5000, 'slidespeed' => 200, 'carousel_skin' => '', 'desktop' => 4, 'desktopsmall' => 3, 'tablet' => 2, 'mobile' => 1, 'gutters' => false, 'navigation' => true, 'navigation_always_on' => false, 'navigation_position' => 'center-outside', 'navigation_style' => 'normal', 'pagination' => false, 'pagination_position' => 'center-bottom', 'pagination_style' => 'dot-stroke', 'css_animation' => '', 'el_class' => '', 'css' => ''), $atts);
extract($atts);
$elementClass = array('base' => apply_filters(VC_SHORTCODE_CUSTOM_CSS_FILTER_TAG, 'products-carousel ', $this->settings['base'], $atts), 'extra' => $this->getExtraClass($el_class), 'css_animation' => $this->getCSSAnimation($css_animation), 'woocommerce' => 'woocommerce columns-' . $desktop, 'shortcode_custom' => vc_shortcode_custom_css_class($css, ' '), 'layout' => 'layout-' . $layout);
$meta_query = WC()->query->get_meta_query();
if ($source == 'best-sellers') {
$meta_key = 'total_sales';
$orderby = 'meta_value_num';
}
$args = array('post_type' => 'product', 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'posts_per_page' => $per_page, 'meta_query' => $meta_query, 'order' => $order, 'orderby' => $orderby, 'meta_key' => $meta_key);
if ($source == 'onsale') {
$product_ids_on_sale = wc_get_product_ids_on_sale();
$args['post__in'] = array_merge(array(0), $product_ids_on_sale);
} elseif ($source == 'featured') {
$args['meta_query'][] = array('key' => '_featured', 'value' => 'yes');
} elseif ($source == 'top-rated') {
add_filter('posts_clauses', array(__CLASS__, 'order_by_rating_post_clauses'));
} elseif ($source == 'categories') {
if (!empty($categories)) {
$args['tax_query'] = array(array('taxonomy' => 'product_cat', 'terms' => array_map('sanitize_title', explode(',', $categories)), 'field' => 'slug', 'operator' => $operator));
}
} elseif ($source == 'products') {
if (!empty($atts['products'])) {
$args['post__in'] = array_map('trim', explode(',', $atts['products']));
}
}
$output = $carousel_html = '';
ob_start();
$products = new WP_Query(apply_filters('woocommerce_shortcode_products_query', $args, $atts));
if ($products->have_posts()) {
global $woocommerce_loop;
$woocommerce_loop['columns'] = $desktop;
$carousel_ouput = cruxstore_render_carousel(apply_filters('cruxstore_render_args', $atts), '', 'wc-carousel-wrapper');
if ($layout == 'transparent') {
$woocommerce_loop['type'] = 'transparent';
} else {
$woocommerce_loop['type'] = 'normal';
}
woocommerce_product_loop_start();
while ($products->have_posts()) {
$products->the_post();
wc_get_template_part('content', 'product');
}
// end of the loop.
woocommerce_product_loop_end();
}
$carousel_html .= ob_get_clean();
wp_reset_postdata();
if ($carousel_html) {
$elementClass = preg_replace(array('/\\s+/', '/^\\s|\\s$/'), array(' ', ''), implode(' ', $elementClass));
$output = '<div class="' . esc_attr($elementClass) . '">' . str_replace('%carousel_html%', $carousel_html, $carousel_ouput) . '</div>';
}
return $output;
}
示例4: new_products_lightspeed
function new_products_lightspeed($atts)
{
/**
* Featured Products shortcode
*
* @param array $atts
* @return string
*/
global $woocommerce_loop, $products, $product;
// include our handy API wrapper that makes it easy to call the API, it also depends on MOScURL to make the cURL call
require_once "MOSAPICall.class.php";
extract(shortcode_atts(array('per_page' => '12', 'columns' => '4', 'orderby' => 'date', 'order' => 'desc'), $atts));
$woocommerce_loop['columns'] = $columns;
ob_start();
$mosapi = new MOSAPICall("992e498dfa5ab5245f5bd5afee4ee1ce6ac6e0a1ee7d11e36480694a9b5282e7", "83442");
$emitter = 'https://api.merchantos.com/API/Account/83442/ItemMatrix';
$xml_query_string = 'limit=100&orderby=timeStamp&orderby_desc=1&load_relations=["ItemECommerce","Tags","Images"]';
$products = $mosapi->makeAPICall("Account.ItemMatrix", "Read", null, null, $emitter, $xml_query_string);
$wp_session = WP_Session::get_instance();
$products = xml2array($products);
$wp_session['products'] = $products;
//var_dump($wp_session['products']);
$i = 0;
//if ( $products->children() ) :
?>
<?php
woocommerce_product_loop_start();
?>
<?php
foreach ($products as $prod) {
foreach ($prod as $product) {
wc_get_template_part('content', 'lightspeedproduct');
}
}
// end of the loop.
?>
<?php
woocommerce_product_loop_end();
?>
<?php
//endif;
return '<div class="woocommerce columns-' . $columns . '">' . ob_get_clean() . '</div>';
}
示例5: content
protected function content($atts, $content = null)
{
$atts = shortcode_atts(array('desktop' => 3, 'per_page' => 10, 'orderby' => 'date', 'meta_key' => '', 'order' => 'DESC', 'source' => 'all', 'categories' => '', 'products' => '', 'operator' => 'IN', 'css_animation' => '', 'el_class' => '', 'css' => ''), $atts);
extract($atts);
$elementClass = array('base' => apply_filters(VC_SHORTCODE_CUSTOM_CSS_FILTER_TAG, 'cruxstore-products-countdown', $this->settings['base'], $atts), 'extra' => $this->getExtraClass($el_class), 'css_animation' => $this->getCSSAnimation($css_animation), 'woocommerce' => 'woocommerce columns-' . $desktop, 'shortcode_custom' => vc_shortcode_custom_css_class($css, ' '));
$meta_query = WC()->query->get_meta_query();
$product_ids_on_sale = wc_get_product_ids_on_sale();
$args = array('post_type' => 'product', 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'posts_per_page' => $atts['per_page'], 'meta_query' => $meta_query, 'order' => $order, 'orderby' => $orderby, 'meta_key' => $meta_key, 'post__in' => array_merge(array(0), $product_ids_on_sale));
if ($source == 'categories') {
if (!empty($categories)) {
$args['tax_query'] = array(array('taxonomy' => 'product_cat', 'terms' => array_map('sanitize_title', explode(',', $categories)), 'field' => 'slug', 'operator' => $operator));
}
} elseif ($source == 'products') {
if (!empty($atts['products'])) {
$args['post__in'] = array_map('trim', explode(',', $atts['products']));
}
}
$output = '';
ob_start();
global $woocommerce_loop;
$products = new WP_Query(apply_filters('woocommerce_shortcode_products_query', $args, $atts));
$woocommerce_loop['columns'] = $desktop;
$woocommerce_loop['type'] = 'countdown';
if ($products->have_posts()) {
woocommerce_product_loop_start();
while ($products->have_posts()) {
$products->the_post();
wc_get_template_part('content', 'product_sale');
}
// end of the loop.
woocommerce_product_loop_end();
}
wp_reset_postdata();
$output .= ob_get_clean();
$elementClass = preg_replace(array('/\\s+/', '/^\\s|\\s$/'), array(' ', ''), implode(' ', $elementClass));
return '<div class="' . esc_attr($elementClass) . '">' . $output . '</div>';
}
示例6: wr_ferado_product_slider
function wr_ferado_product_slider($atts, $content = null)
{
$limit = $orderby = $order = $single = $class = $effect_output = '';
extract(shortcode_atts(array('limit' => '10', 'orderby' => 'date', 'order' => 'desc', 'pagination' => 'false', 'navigation' => 'false', 'item' => 6, 'single' => 'false', 'cat' => '', 'title' => '', 'full' => '', 'effect' => ''), $atts));
global $product, $woocommerce_loop, $post;
// The meta query for the page
$meta_query = WC()->query->get_meta_query();
// Generate random id
$length = 10;
$id = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, $length);
// Filter product post type
$args = array('post_type' => 'product', 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'orderby' => $orderby, 'order' => $order, 'meta_query' => $meta_query, 'posts_per_page' => $limit);
if (!empty($cat)) {
$args['tax_query'] = array('relation' => 'AND', array('taxonomy' => 'product_cat', 'field' => 'id', 'terms' => explode(',', $cat)));
}
if ($effect) {
$effect_output = '
beforeMove: updateCarousel,
afterInit: function() {
setTimeout(updateCarousel, 100)
}';
}
ob_start();
$products = new WP_Query(apply_filters('woocommerce_shortcode_products_query', $args, $atts));
echo '
<scr' . 'ipt>
(function($) {
"use strict";
$(document).ready(function() {
var owl = $("#' . $id . '");
owl.owlCarousel({
navigation: ' . $navigation . ',
navigationText: [
"<i class=\\"dashicons dashicons-arrow-left-alt2\\"></i>",
"<i class=\\"dashicons dashicons-arrow-right-alt2\\"></i>",
],
pagination: ' . $pagination . ',
singleItem: ' . $single . ',
items: ' . $item . ',
itemsMobile : [540,1],
itemsTablet : [768,2],
itemsDesktopSmall : [1366,4],
itemsDesktop: [1920,6],
slideSpeed : 600,
' . $effect_output . '
});
function updateCarousel() {
var start = data.currentItem;
var count = data.options.items;
if ( window.innerWidth < 1921 ) {
var endStart = start+count-1;
var first2 = owl.find(".owl-item").slice(start,start+1);
var last2 = owl.find(".owl-item").slice(endStart, endStart+1);
} else {
var endStart = start+count-2;
var first2 = owl.find(".owl-item").slice(start,start+2);
var last2 = owl.find(".owl-item").slice(endStart, endStart+2);
}
owl.find(".owl-item").removeClass("blur");
first2.addClass("blur");
last2.addClass("blur");
}
var data = owl.data("owlCarousel");
});
})(jQuery);
</scr' . 'ipt>';
if ('true' == $single) {
$class .= 'single-gal';
}
if ('true' != $single && $title) {
echo '<div class="h-slider"><h4 class="slider-title">' . $title . '</h4></div>';
}
// Begin the loop
if ($products->have_posts()) {
if (function_exists('woocommerce_product_loop_start')) {
woocommerce_product_loop_start();
}
?>
<div id="<?php
echo $id;
?>
" class="owl-carousel <?php
echo $class;
?>
">
<?php
while ($products->have_posts()) {
$products->the_post();
global $product;
$cat_count = sizeof(get_the_terms($post->ID, 'product_cat'));
$tag_count = sizeof(get_the_terms($post->ID, 'product_tag'));
?>
<li <?php
post_class();
?>
>
//.........这里部分代码省略.........
示例7: output
/**
* Output shortcode
*
* @access public
* @param array $atts
* @return void
*
*/
public static function output($atts)
{
global $woocommerce, $wpdb;
extract(shortcode_atts(array('show_buy_it_now' => 'false'), $atts));
if (!is_user_logged_in()) {
return;
}
$user_id = get_current_user_id();
$postids = array();
$userauction = $wpdb->get_results("SELECT DISTINCT auction_id FROM " . $wpdb->prefix . "simple_auction_log WHERE userid = {$user_id} ", ARRAY_N);
if (isset($userauction) && !empty($userauction)) {
foreach ($userauction as $auction) {
$postids[] = $auction[0];
}
}
?>
<div class="simple-auctions active-auctions clearfix">
<h2><?php
_e('Active auctions', 'wc_simple_auctions');
?>
</h2>
<?php
$args = array('post__in' => $postids, 'post_type' => 'product', 'posts_per_page' => '-1', 'order' => 'ASC', 'orderby' => 'meta_value', 'tax_query' => array(array('taxonomy' => 'product_type', 'field' => 'slug', 'terms' => 'auction')), 'meta_query' => array(array('key' => '_auction_closed', 'compare' => 'NOT EXISTS')), 'auction_arhive' => TRUE, 'show_past_auctions' => FALSE);
//var_dump($args);
$activeloop = new WP_Query($args);
//var_dump($activeloop);
if ($activeloop->have_posts() && !empty($postids)) {
woocommerce_product_loop_start();
while ($activeloop->have_posts()) {
$activeloop->the_post();
woocommerce_get_template_part('content', 'product');
}
woocommerce_product_loop_end();
} else {
_e("You are not participating in auction.", "wc_simple_auctions");
}
wp_reset_postdata();
?>
</div>
<div class="simple-auctions active-auctions clearfix">
<h2><?php
_e('Won auctions', 'wc_simple_auctions');
?>
</h2>
<?php
$auction_closed_type[] = '2';
if ($show_buy_it_now == 'true') {
$auction_closed_type[] = '3';
}
$args = array('post_type' => 'product', 'posts_per_page' => '-1', 'order' => 'ASC', 'orderby' => 'meta_value', 'meta_key' => '_auction_dates_to', 'meta_query' => array(array('key' => '_auction_closed', 'value' => $auction_closed_type, 'compare' => 'IN'), array('key' => '_auction_current_bider', 'value' => $user_id)), 'show_past_auctions' => TRUE, 'auction_arhive' => TRUE);
$winningloop = new WP_Query($args);
if ($winningloop->have_posts() && !empty($postids)) {
woocommerce_product_loop_start();
while ($winningloop->have_posts()) {
$winningloop->the_post();
woocommerce_get_template_part('content', 'product');
}
woocommerce_product_loop_end();
} else {
_e("You did not win any auctions yet.", "wc_simple_auctions");
}
wp_reset_postdata();
echo "</div>";
}
示例8: get_products
/**
* Loop over found products.
*
* @since 1.0.0
* @param array $query_args \WP_Query arguments.
* @param array $atts User defined attributes in shortcode tag.
* @return string Current buffer contents.
*/
private function get_products($query_args, $atts)
{
global $woocommerce_loop;
$category = \sanitize_title($atts['category']);
$taxonomy = \sanitize_text_field($atts['taxonomy']);
$columns = absint($atts['columns']);
$woocommerce_loop['columns'] = $columns;
$products = new \WP_Query($query_args);
ob_start();
if ($products->have_posts()) {
\do_action('woocommerce_shortcode_before_featured_products_by_category', $category, $taxonomy);
\woocommerce_product_loop_start();
while ($products->have_posts()) {
$products->the_post();
\wc_get_template_part('content', 'product');
}
\woocommerce_product_loop_end();
\do_action('woocommerce_shortcode_after_featured_products_by_category', $category, $taxonomy);
}
\woocommerce_reset_loop();
\wp_reset_postdata();
return '<div class="woocommerce columns-' . $columns . '">' . ob_get_clean() . '</div>';
}
示例9: fruitful_woocommerce_cross_sell_display
function fruitful_woocommerce_cross_sell_display()
{
if (!defined('ABSPATH')) {
exit;
}
// Exit if accessed directly
global $woocommerce_loop, $woocommerce, $product;
$crosssells = $woocommerce->cart->get_cross_sells();
if (sizeof($crosssells) == 0) {
return;
}
$meta_query = $woocommerce->query->get_meta_query();
$args = array('post_type' => 'product', 'ignore_sticky_posts' => 1, 'posts_per_page' => apply_filters('woocommerce_cross_sells_total', 4), 'no_found_rows' => 1, 'orderby' => 'rand', 'post__in' => $crosssells, 'meta_query' => $meta_query);
$products = new WP_Query($args);
$woocommerce_loop['columns'] = apply_filters('woocommerce_cross_sells_columns', 4);
if ($products->have_posts()) {
?>
<div class="cross-sells">
<h2><?php
_e('You may be interested in…', 'woocommerce');
?>
</h2>
<?php
woocommerce_product_loop_start();
?>
<?php
while ($products->have_posts()) {
$products->the_post();
?>
<?php
woocommerce_get_template_part('content', 'product');
?>
<?php
}
// end of the loop.
?>
<?php
woocommerce_product_loop_end();
?>
</div>
<?php
}
wp_reset_query();
}
示例10: woof_products
//.........这里部分代码省略.........
<?php
//if (!get_option('woof_try_ajax')):
?>
<div id="woof_results_by_ajax" class="woof_results_by_ajax_shortcode" data-shortcode="<?php
echo $shortcode_txt;
?>
">
<?php
//endif;
?>
<?php
}
?>
<?php
if ($products->have_posts()) {
add_filter('post_class', array($this, 'woo_post_class'));
$_REQUEST['woof_before_shop_loop_done'] = true;
?>
<div class="woocommerce columns-<?php
echo $columns;
?>
woocommerce-page woof_shortcode_output">
<?php
if ($dp == 0) {
//Display Product for WooCommerce compatibility
do_action('woocommerce_before_shop_loop');
}
?>
<?php
if (function_exists('woocommerce_product_loop_start')) {
woocommerce_product_loop_start();
}
?>
<?php
global $woocommerce_loop;
$woocommerce_loop['columns'] = $columns;
$woocommerce_loop['loop'] = 0;
//+++
wc_get_template('loop/loop-start.php');
//WOOCS compatibility
global $WOOCS;
if (!method_exists($WOOCS, 'woocs_convert_currency')) {
if (class_exists('WOOCS') and defined('DOING_AJAX')) {
//IT IS OBSOLETE AND NOT RIGHT ALREADY FROM X.0.9 VERSIONS
//add_filter('raw_woocommerce_price', array($this, 'raw_woocommerce_price'), 1001);
//add_filter('woocommerce_currency_symbol', array($this, 'woocommerce_currency_symbol'), 1001);
}
}
?>
<?php
//products output
if ($dp == 0) {
//Display Product for WooCommerce compatibility
while ($products->have_posts()) {
$products->the_post();
wc_get_template_part('content', 'product');
}
// end of the loop.
示例11: do_action_output_related_products
public static function do_action_output_related_products($initargs)
{
global $product, $woocommerce_loop, $pwyw_related_product;
$show_related = get_option(self::ID . '_show_related_products');
if ($show_related == 'yes' || $show_related == '1') {
$pwyw_related_product = true;
$posts_per_page = 2;
$columns = $woocommerce_loop['columns'];
if (!isset($columns)) {
$columns = 2;
}
$orderby = 'rand';
$related = $product->get_related($posts_per_page);
if (sizeof($related) == 0) {
return;
}
$args = apply_filters('woocommerce_related_products_args', array('post_type' => 'product', 'pwyw_type' => 'related', 'ignore_sticky_posts' => 1, 'no_found_rows' => 1, 'posts_per_page' => $posts_per_page, 'orderby' => $orderby, 'post__in' => $related, 'post__not_in' => array($product->id)));
$products = new WP_Query($args);
$woocommerce_loop['columns'] = $columns;
if ($products->have_posts()) {
echo '<div class="related products">';
echo ' <h2>' . __('Related Products', 'woocomerce') . '</h2>';
woocommerce_product_loop_start();
echo " <ul>";
while ($products->have_posts()) {
$products->the_post();
wc_get_template_part('content', 'product');
}
echo " </ul>";
woocommerce_product_loop_end();
echo '</div>';
}
wp_reset_postdata();
$pwyw_related_product = false;
}
}
示例12: woof_products
//.........这里部分代码省略.........
?>
<?php
}
?>
<?php
if ($products->have_posts()) {
add_filter('post_class', array($this, 'woo_post_class'));
$_REQUEST['woof_before_shop_loop_done'] = true;
?>
<div class="woocommerce columns-<?php
echo $columns;
?>
woocommerce-page woof_shortcode_output">
<?php
$show_loop_filters = true;
//for attribute behavior of the shortcode
if (!empty($behavior)) {
if ($behavior == 'recent') {
$show_loop_filters = false;
}
}
if ($dp == 0) {
//Display Product for WooCommerce compatibility
if ($show_loop_filters) {
do_action('woocommerce_before_shop_loop');
}
}
?>
<?php
if (function_exists('woocommerce_product_loop_start')) {
woocommerce_product_loop_start();
}
?>
<?php
global $woocommerce_loop;
$woocommerce_loop['columns'] = $columns;
$woocommerce_loop['loop'] = 0;
//+++
//wc_get_template('loop/loop-start.php');
?>
<?php
//products output
if ($dp == 0) {
//Display Product for WooCommerce compatibility
while ($products->have_posts()) {
$products->the_post();
wc_get_template_part('content', 'product');
}
// end of the loop.
} else {
echo do_shortcode('[displayProduct id="' . $dp . '"]');
}
?>
<?php
//wc_get_template('loop/loop-end.php');
示例13: product
/**
* Display a single product.
*
* @param array $atts
* @return string
*/
public static function product($atts)
{
if (empty($atts)) {
return '';
}
$meta_query = WC()->query->get_meta_query();
$args = array('post_type' => 'product', 'posts_per_page' => 1, 'no_found_rows' => 1, 'post_status' => 'publish', 'meta_query' => $meta_query);
if (isset($atts['sku'])) {
$args['meta_query'][] = array('key' => '_sku', 'value' => $atts['sku'], 'compare' => '=');
}
if (isset($atts['id'])) {
$args['p'] = $atts['id'];
}
ob_start();
$products = new WP_Query(apply_filters('woocommerce_shortcode_products_query', $args, $atts));
if ($products->have_posts()) {
?>
<?php
woocommerce_product_loop_start();
?>
<?php
while ($products->have_posts()) {
$products->the_post();
?>
<?php
wc_get_template_part('content', 'product');
?>
<?php
}
// end of the loop.
?>
<?php
woocommerce_product_loop_end();
?>
<?php
}
wp_reset_postdata();
$css_class = 'woocommerce';
if (isset($atts['class'])) {
$css_class .= ' ' . $atts['class'];
}
return '<div class="' . esc_attr($css_class) . '">' . ob_get_clean() . '</div>';
}
示例14: zwt_woocommerce_customer_also_viewed
/**
*
* @global type $woocommerce
* @global type $post
*/
function zwt_woocommerce_customer_also_viewed($atts, $content = null)
{
$per_page = get_option('total_items_display');
$plugin_title = get_option('customer_who_viewed_title');
$category_filter = get_option('category_filter');
$show_image_filter = get_option('show_image_filter');
$show_price_filter = get_option('show_price_filter');
$show_addtocart_filter = get_option('show_addtocart_filter');
$product_order = get_option('product_order');
// Get WooCommerce Global
global $woocommerce;
global $post;
// Get recently viewed product data using get_option
$customer_also_viewed = get_option('customer_also_viewed_' . $post->ID);
if (!empty($customer_also_viewed)) {
$customer_also_viewed = explode(',', $customer_also_viewed);
$customer_also_viewed = array_reverse($customer_also_viewed);
//Skip same product on product page from the list
if (($key = array_search($post->ID, $customer_also_viewed)) !== false) {
unset($customer_also_viewed[$key]);
}
$per_page = $per_page == "" ? $per_page = 5 : $per_page;
$plugin_title = $plugin_title == "" ? $plugin_title = 'Customer Who Viewed This Item Also Viewed' : $plugin_title;
// Create the object
ob_start();
$categories = get_the_terms($post->ID, 'product_cat');
// Create query arguments array
$query_args = array('posts_per_page' => $per_page, 'no_found_rows' => 1, 'post_status' => 'publish', 'post_type' => 'product', 'post__in' => $customer_also_viewed);
$query_args['orderby'] = $product_order == '' ? 'ID(ID, explode(' . $customer_also_viewed . '))' : $product_order;
//Executes if category filter applied on product page
if ($category_filter == 1 && !empty($categories)) {
foreach ($categories as $category) {
if ($category->parent == 0) {
$category_slug = $category->slug;
}
}
$query_args['product_cat'] = $category_slug;
}
// Add meta_query to query args
$query_args['meta_query'] = array();
// Check products stock status
$query_args['meta_query'][] = $woocommerce->query->stock_status_meta_query();
// Create a new query
$products = new WP_Query($query_args);
// If query return results
if (!$products->have_posts()) {
// If no data, quit
exit;
} else {
//Displays title
?>
<h2><?php
_e($plugin_title, 'woocommerce');
?>
</h2>
<div class="clear">
<div class="woocommerce customer_also_viewed">
<?php
// Start the loop
$count = 1;
woocommerce_product_loop_start();
while ($products->have_posts()) {
$products->the_post();
?>
<li class="product">
<?php
do_action('woocommerce_before_shop_loop_item');
?>
<a href="<?php
the_permalink();
?>
">
<?php
if ($show_image_filter == 1) {
do_action('woocommerce_before_shop_loop_item_title');
}
?>
<!--<h3><?php
/*the_title();; */
?>
</h3>-->
<?php
if ($show_price_filter == 1) {
do_action('woocommerce_after_shop_loop_item_title');
}
?>
</a>
<?php
if ($show_addtocart_filter == 1) {
do_action('woocommerce_after_shop_loop_item');
}
?>
</li>
//.........这里部分代码省略.........
示例15: content
protected function content($atts, $content = null)
{
$atts = shortcode_atts(array('title' => esc_html__('Title', 'js_composer'), 'source' => 'widgets', 'categories' => '', 'per_page' => 8, 'orderby' => 'date', 'order' => 'DESC', 'style' => 1, 'active_section' => 1, 'font_size' => '', 'line_height' => '', 'letter_spacing' => '', 'font_container' => '', 'use_theme_fonts' => 'yes', 'google_fonts' => '', 'css_animation' => '', 'el_class' => '', 'css' => '', 'operator' => 'IN'), $atts);
$columns = 3;
$product_type = 'classic';
// This is needed to extract $font_container_data and $google_fonts_data
extract($this->getAttributes($atts));
unset($font_container_data['values']['text_align']);
$atts = vc_map_get_attributes($this->getShortcode(), $atts);
extract($atts);
extract($this->getStyles($el_class, $css, $google_fonts_data, $font_container_data, $atts));
$settings = get_option('wpb_js_google_fonts_subsets');
if (is_array($settings) && !empty($settings)) {
$subsets = '&subset=' . implode(',', $settings);
} else {
$subsets = '';
}
if (isset($google_fonts_data['values']['font_family'])) {
wp_enqueue_style('vc_google_fonts_' . vc_build_safe_css_class($google_fonts_data['values']['font_family']), '//fonts.googleapis.com/css?family=' . $google_fonts_data['values']['font_family'] . $subsets);
}
if ($letter_spacing) {
if (empty($styles)) {
$styles = array();
}
$styles[] = 'letter-spacing: ' . $letter_spacing . 'px';
}
if (!empty($styles)) {
$style = 'style="' . esc_attr(implode(';', $styles)) . '"';
} else {
$style = '';
}
$elementClass = array('base' => apply_filters(VC_SHORTCODE_CUSTOM_CSS_FILTER_TAG, 'wc-products-vertical', $this->settings['base'], $atts), 'extra' => $this->getExtraClass($el_class), 'css_animation' => $this->getCSSAnimation($css_animation), 'shortcode_custom' => vc_shortcode_custom_css_class($css, ' '), 'product_stype' => 'cruxstore-products cruxstore-products-classic', 'woocommerce' => 'woocommerce columns-' . $columns);
if (!$active_section) {
$active_section = 1;
}
$uniqeID = uniqid();
$meta_query = WC()->query->get_meta_query();
$args = array('post_type' => 'product', 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'posts_per_page' => $atts['per_page'], 'meta_query' => $meta_query);
if ($source == 'categories') {
$tabs = explode(',', $categories);
$args['order'] = $order;
$args['orderby'] = $orderby;
} else {
$tabs = array('onsale', 'new', 'bestselling');
}
$tab_heading = '<ul class="nav-style" data-count="' . count($tabs) . '">';
$i = 1;
foreach ($tabs as $tab) {
if ($source == 'categories') {
$term = get_term_by('slug', sanitize_title($tab), 'product_cat');
$text = $term->name;
} else {
if ($tab == 'new') {
$text = esc_html__('Arrivals Products', 'cruxstore');
} elseif ($tab == 'bestselling') {
$text = esc_html__('Best Sellers', 'cruxstore');
} elseif ($tab == 'onsale') {
$text = esc_html__('On sale', 'cruxstore');
}
}
$class = $active_section == $i ? ' class="active"' : '';
$tab_heading .= sprintf('<li %s><a href="%s" data-toggle="tab"><span data-hover="%s">%s</span></a></li>', $class, '#tab-' . $tab . '-' . $uniqeID, esc_attr($text), $text);
$i++;
}
$tab_heading .= "</ul>";
global $woocommerce_loop;
$i = 1;
$output_content = '';
$carousel_atts = array('desktop' => $columns, 'navigation' => false, 'gutters' => false);
$carousel_ouput = cruxstore_render_carousel(apply_filters('cruxstore_render_args', $carousel_atts), '', 'wc-carousel-wrapper');
foreach ($tabs as $tab) {
$new_args = $args;
if ($source == 'categories') {
$new_args['tax_query'] = array(array('taxonomy' => 'product_cat', 'terms' => sanitize_title($tab), 'field' => 'slug', 'operator' => $atts['operator']));
} else {
if ($tab == 'bestselling') {
$new_args['meta_key'] = 'total_sales';
$new_args['orderby'] = 'meta_value_num';
} elseif ($tab == 'featured') {
$new_args['meta_query'][] = array('key' => '_featured', 'value' => 'yes');
} elseif ($tab == 'onsale') {
$new_args['post__in'] = array_merge(array(0), wc_get_product_ids_on_sale());
}
}
$products = new WP_Query(apply_filters('woocommerce_shortcode_products_query', $new_args, $atts));
$woocommerce_loop['columns'] = $columns;
$woocommerce_loop['type'] = $product_type;
ob_start();
if ($products->have_posts()) {
woocommerce_product_loop_start();
while ($products->have_posts()) {
$products->the_post();
wc_get_template_part('content', 'product');
}
// end of the loop.
woocommerce_product_loop_end();
}
wp_reset_postdata();
$carousel_html = ob_get_clean();
$carousel_html = str_replace('%carousel_html%', $carousel_html, $carousel_ouput);
//.........这里部分代码省略.........