List Variation Products in Category
-
Sorry my bad english, I’m trying to make the listing of variables products and I am almost there, my only problem is in relation to Post Class with the first and last classes, I believe the problem is the keys that were not created sequentially with it is listed products not in 4 columns as I wish but in 3, 2 or even a, below my code created in product-content.php, someone could help me?
<?php
/**
* The template for displaying product content within loops.
*
* Override this template by copying it to yourtheme/woocommerce/content-product.php
*
* @author WooThemes
* @package WooCommerce/Templates
* @version 1.6.4
*/if ( ! defined( ‘ABSPATH’ ) ) exit; // Exit if accessed directly
global $product, $woocommerce_loop;
// Store loop count we’re currently on
if ( empty( $woocommerce_loop[‘loop’] ) )
$woocommerce_loop[‘loop’] = 0;// Store column count for displaying the grid
if ( empty( $woocommerce_loop[‘columns’] ) )
$woocommerce_loop[‘columns’] = apply_filters( ‘loop_shop_columns’, 4 );// Ensure visibility
if ( ! $product || ! $product->is_visible() )
return;// Increase loop count
$woocommerce_loop[‘loop’]++;// Extra post classes
$classes = array();
if ( 0 == ( $woocommerce_loop[‘loop’] – 1 ) % $woocommerce_loop[‘columns’] || 1 == $woocommerce_loop[‘columns’] )
$classes[] = ‘first’;
if ( 0 == $woocommerce_loop[‘loop’] % $woocommerce_loop[‘columns’] )
$classes[] = ‘last’;if( $product->is_type( ‘simple’ ) ){
// a simple product?>
<li <?php post_class( $classes ); ?>><?php do_action( ‘woocommerce_before_shop_loop_item’ ); ?>
<?php
/**
* woocommerce_before_shop_loop_item_title hook
*
* @hooked woocommerce_show_product_loop_sale_flash – 10
* @hooked woocommerce_template_loop_product_thumbnail – 10
*/
do_action( ‘woocommerce_before_shop_loop_item_title’ );
?><h3><?php the_title(); ?></h3>
<?php
/**
* woocommerce_after_shop_loop_item_title hook
*
* @hooked woocommerce_template_loop_rating – 5
* @hooked woocommerce_template_loop_price – 10
*/
do_action( ‘woocommerce_after_shop_loop_item_title’ );
?><?php do_action( ‘woocommerce_after_shop_loop_item’ ); ?>
<?php
} if( $product->is_type( ‘variable’ ) ){
// a variable productif( is_product_category() ) :
foreach( $product->get_children() as $key => $img){
//echo $key;
//echo $woocommerce_loop[‘loop’]++;
$array[$key] .= wp_get_attachment_thumb_url( get_post_thumbnail_id($img));//$id = implode(”,$unique);
$unique = array_unique($array);}
$args = array(
‘post_type’ => ‘product_variation’,
);
$loop = new WP_Query( $args );if ( $loop->have_posts() ) {
while ( $loop->have_posts() ) : $loop->the_post();
// Store loop count we’re currently on
//echo $loop->post->ID;
$img = $product->get_children();
//$array[$loop->post->ID] .= wp_get_attachment_thumb_url( get_post_thumbnail_id($img));
// $unique = array_unique($array);//$meta = get_post_meta($loop->post->ID);
//print_r($unique. $ID = $loop->post->ID;);
//$implode = implode(”,$unique);
// print_r($loop->post->ID);
endwhile;//print_r($unique);
if ( empty( $woocommerce_loop[‘loop’] ) )
$woocommerce_loop[‘loop’] = 0;// Store column count for displaying the grid
if ( empty( $woocommerce_loop[‘columns’] ) )
$woocommerce_loop[‘columns’] = apply_filters( ‘loop_shop_columns’, 4 );// Ensure visibility
if ( ! $product || ! $product->is_visible() )
return;
//print_r($unique);
foreach ($unique as $key => $uniques){
$woocommerce_loop[‘loop’]++;
$classes = array();
if ( 0 == ( $woocommerce_loop[‘loop’] – 1 ) % $woocommerce_loop[‘columns’] || 1 == $woocommerce_loop[‘columns’] )
$classes[] = ‘first’;
if ( 0 == $woocommerce_loop[‘loop’] % $woocommerce_loop[‘columns’] )
$classes[] = ‘last’;
//echo $key;
$meta = $product->get_available_variations();
$metas = $meta[$key][‘attributes’][‘attribute_pa_cor’];
//print_r($metas);
?><li <?php post_class($classes ); ?>>
get_permalink( ) ?>”>
<?php print_r(‘<img src=”‘.$uniques.'”/>’); ?>
<h3><?php echo $product->get_title() . ” ” . ucfirst($metas); ?></h3>
<span class=’price’><?php echo $product->get_price_html(); ?></span>ou <?php echo do_shortcode(‘[parcela]’).”x de R$ “.do_shortcode(‘[valor]’);?>
<?php
}
}
wp_reset_postdata();
?><?php
endif;
}
?>
The topic ‘List Variation Products in Category’ is closed to new replies.