WordPress.org

Support

Support » Plugins and Hacks » [Resolved] Display icon if product is virtual or downloadable

[Resolved] Display icon if product is virtual or downloadable

  • 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/

Viewing 2 replies - 1 through 2 (of 2 total)
  • 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.

    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]

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Resolved] Display icon if product is virtual or downloadable’ is closed to new replies.