array($post_id), 'posts_per_page' => 1, 'post_status' => 'publish', 'post_type' => 'product', 'tax_query' => array(
array(
'taxonomy' => 'product_cat',
'field' => 'id',
'terms' => $categories_as_array
)));
$r_single = new WP_Query($query_args);
if ($r_single->have_posts()) {
$r_single->the_post();
global $product;
?>
get_image_size('shop_thumbnail_image_width').'" height="'.$woocommerce->get_image_size('shop_thumbnail_image_height').'" />'; ?>
get_price_html(); ?>
ID, 'product_cat' );
foreach ( $terms as $term ) $cats_array[] = $term->term_id;
// get all posts in current categories
$query_args = array('posts_per_page' => -1, 'post_status' => 'publish', 'post_type' => 'product', 'tax_query' => array(
array(
'taxonomy' => 'product_cat',
'field' => 'id',
'terms' => $cats_array
)));
$r = new WP_Query($query_args);
// show next and prev only if we have 3 or more
if ($r->post_count > 2) {
$prev_product_id = -1;
$next_product_id = -1;
$found_product = false;
$i = 0;
$current_product_index = $i;
$current_product_id = get_the_ID();
if ($r->have_posts()) {
while ($r->have_posts()) {
$r->the_post();
$current_id = get_the_ID();
if ($current_id == $current_product_id) {
$found_product = true;
$current_product_index = $i;
}
$is_first = ($current_product_index == $first_product_index);
if ($is_first) {
$prev_product_id = get_the_ID(); // if product is first then 'prev' = last product
} else {
if (!$found_product && $current_id != $current_product_id) {
$prev_product_id = get_the_ID();
}
}
if ($i == 0) { // if product is last then 'next' = first product
$next_product_id = get_the_ID();
}
if ($found_product && $i == $current_product_index + 1) {
$next_product_id = get_the_ID();
}
$i++;
}
echo '
';
}
wp_reset_query();
}
}
?>