WordPress.org

Forums

WooCommerce - excelling eCommerce
[resolved] Display icon if product is virtual or downloadable (3 posts)

  1. Russ Powers
    Member
    Posted 1 year ago #

    So I'm trying to display an icon on the product page that will let customers know if a product is downloadable or virtual. At first I thought a simple php 'if' statement like the one below would suffice, but it doesn't work lol

    <?php
    if ($_product->is_downloadable('yes')) {
    	echo "<img src='downloadable.png'>";
    }else{
    	echo "";
    }
    ?>

    Any advice on this would be greatly appreciated :)

    https://wordpress.org/plugins/woocommerce/

  2. Russ Powers
    Member
    Posted 1 year ago #

    Figured it out! Below is the working code :) Add it anywhere in your product-page template (mine is in the title!)

    <?php
    if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
    global $post, $woocommerce, $product;
    
    if ($product->is_downloadable('yes')) {
    	echo "<img src='downloadable.png'>";
    }else{
    	echo " ";
    }
    ?>

    Same can be done with virtual products by replacing is_downloadable with is_virtual in the snippet above.

  3. Russ Powers
    Member
    Posted 1 year ago #

    So I'm marking this one as resolved. I may write a blog post/tutorial about this in the near future. If anyone's interested it will be at [Link removed]

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.