• Hi,

    I’m creating a custom Upsell template where i only want to display the image of the upsell and title. Linked to the upsell product. What am i doing wrong because the result i get now is: the image gives me a null and the product link links to the product page you are on so not the link of the upsell product.

    So the only thing working now is it is getting the right products and titles of the products, but it is not getting the right link and image.

    Please help

    
    if ( $upsells ) : ?>
    
    	<section class="upselltest">
    		
      <?php woocommerce_product_loop_start(); ?>
    <?php foreach($upsells as $upsell): 
    					
    				$product 	   = wc_get_product( $upsell );
    				$product_title = $upsell->post->post_title;
    				if($product_title == null){continue;}
    				$product_link = get_permalink($upsell);
    				
    				$product_image      = wp_get_attachment_image_src( get_post_thumbnail_id( $pid ), 'shop_thumbnail' );
    				if(isset($product_image[0])){
    					$product_image = $product_image[0];	
    				}else{
    					$product_image = 'null';
    				}
    
    		?>        
            
                <li> 
                  <'a href="<?php echo $product_link; ?>" title="<?php echo $product_title; ?>">
                  <img />" class="attachment-shop_thumbnail size-shop_thumbnail wp-post-image" 
                  alt="<?php echo $product_title; ?>" height="180" width="180"> 
                  <span class="product-title"><?php echo $product_title; ?></span> 
                  </a> 
                  <?php echo $product_price; ?>
                </li>
    
    			<?php endforeach; ?>
    
    • This topic was modified 8 years, 5 months ago by Mixhel.
    • This topic was modified 8 years, 5 months ago by Mixhel.
    • This topic was modified 8 years, 5 months ago by Mixhel.
    • This topic was modified 8 years, 5 months ago by Mixhel.
    • This topic was modified 8 years, 5 months ago by Mixhel.
    • This topic was modified 8 years, 5 months ago by Jan Dembowski. Reason: Fixed code block

The topic ‘Custom Upsell template’ is closed to new replies.