Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1298840

    Rather than having the product page open upon click of the image, I would like an add to cart button to display within the list.

    I would also like the ability to zoom or open the lightbox by clicking on the thumbnail so that the user can better view the image.

    Can you direct me to CSS or a plugin to achieve this?

    #1299594

    Hey Beth,

    Thank you for the inquiry.

    You can use this filter in the functions.php file to insert an “Add to Cart” text next to the excerpt in the catalogue item.

    add_filter("get_the_excerpt", function($excerpt, $post) {
    	if(get_post_type($post->ID) == "product") $excerpt .= "<strong class='avia-catalogue-add-to-cart'>Add to Cart</strong>";
    	return $excerpt;
    }, 10, 2);
    

    Best regards,
    Ismael

    #1299670

    Is there a way to make this an actual “Add to Cart” button, which adds the item to the cart, rather than just a link to the product page?

    • This reply was modified 3 years, 7 months ago by cinchmedia.
    #1300103

    Hi,

    That should be possible but you have to disable the product list option that applies an add to cart link to the whole item. Then replace the snippet with this one to render an actual add to cart button with a link.

    add_filter("get_the_excerpt", function($excerpt, $post) {
    	if(get_post_type($post->ID) == "product") {
    			ob_start();
    			/**
    			 * hooked by: add_action( '<a href='https://refer.wordpress.com/r/84/woocommerce/' target='_blank' rel="nofollow">woocommerce</a>_single_product_summary', '<a href='https://refer.wordpress.com/r/84/woocommerce/' target='_blank' rel="nofollow">woocommerce</a>_template_single_add_to_cart', 30 );
    			*/
    			do_action( '<a href='https://refer.wordpress.com/r/84/woocommerce/' target='_blank' rel="nofollow">woocommerce</a>_single_product_summary' );
    			$cart = ob_get_clean();
    
    			$excerpt .= $cart;
    	}
    	return $excerpt;
    }, 10, 2);
    

    Best regards,
    Ismael

    #1302232

    Is there a way to have both Add to Cart and See Details within the Product List? My customer has some products that the grid format does not work well. He would like simply the image, the title, price and Add to Cart or See Details.

    #1302608

    Hi,

    That should be possible. Make sure to set the element’s Advanced > Link Behavior > Item Links to the first option, then replace the filter with the following.

    add_filter("get_the_excerpt", function($excerpt, $post) {
    	if(get_post_type($post->ID) == "product") {
    		$product = wc_get_product($post->ID);
    		$excerpt .= "<a class='avia-catalogue-add-to-cart' href='" . $product->add_to_cart_url() ."'>Add to Cart</a>";
    	}
    
    	return $excerpt;
    }, 10, 2);
    

    The rest of the product list should link to the actual product page aside from the add to cart button.

    Best regards,
    Ismael

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.