add_action('woocommerce_before_add_to_cart_form', 'show_cross_sell_in_single_product', 30);
function show_cross_sell_in_single_product(){
$crosssells = get_post_meta( get_the_ID(), '_crosssell_ids',true);
if(empty($crosssells)){
return;
}
$args = array(
'post_type' => 'product',
'posts_per_page' => -1,
'post__in' => $crosssells
);
$products = new WP_Query( $args );
if( $products->have_posts() ) :
echo '<div class="thrclrs">';
echo '<span>Andere kleuren</span>';
while ( $products->have_posts() ) : $products->the_post();
global $product;
$kleur = $product->get_attribute( 'pa_kleur' );
?>
<a href="<?php the_permalink(); ?>" title="<?php the_title();?>">
<div class="crssll <?php echo sanitize_title($kleur); ?>"></div>
</a>
<?php
endwhile;
echo '</div>';
endif;
wp_reset_query();
}
#custom #functions #product #single #woocommerce