Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Contributor Ewout

    (@pomegranate)

    Hi! You could, if you loop through the order items and get the image for each product, but that is quite an advanced customization. Alternatively, we do offer the option to show the product / product variation thumbnail with the Premium Templates extension, but I’m not sure if that is what you are after?

    Ewout

    Thread Starter andyzz8

    (@andyzz)

    Hi Ewout,

    Thanks for the message and the plugin!

    The product / product variation thumbnail isn’t what I am after.

    I guess I will need to use this:
    get_template_path(); ?>/image.jpg”/>;
    but I don’t know how to change it to select image X for product X, image Y for product Y, ect.

    Found this but I don’t think it is suitable:
    if ($reviews[‘reviews’][‘freshness’] == ‘fresh’) {
    $image = “fresh”;
    }
    else {
    $image = “rotten”;
    }

    echo ‘Rotten‘;

    • This reply was modified 7 years ago by andyzz8.
    Plugin Contributor kluver

    (@kluver)

    Hi @andyzz,

    If I understand correctly you would like to change the image if a certain product is in the order? You could create a custom template and in the items loop check if your product is in the order like this:

    if( $item_id == your_item_ID_here ) { $change_image = true; }

    Then show a different image on your invoice if $change_image is true. But this requires some coding skills.

    If you need help setting this up I would recommend purchasing one of our paid extensions. The Pro extension or the Premium Templates extension. With it you will get our premium support and we can help you out.

    I hope this answers your question.

    Thread Starter andyzz8

    (@andyzz)

    Thanks for that @kluver

    For example, I want image ‘test1′ to be on the invoice when product ’16’ is purchased, image ‘test2′ to be on the invoice when product ’17’ is purchased ect.

    I tried the below but no image appeared on the invoice.
    I added this to the invoice template:

    <?php
    if( $item_id == '16' ) {
                echo '<img src="https://example.com/wp-content/uploads/test1.png" />';
    }
    ?>
    
    <?php
    if( $item_id == '17' ) {
                echo '<img src="https://example.com/wp-content/uploads/test2.png" />';
    }
    ?>
    Plugin Contributor Ewout

    (@pomegranate)

    @andyzz is that in the items loop part of the invoice (foreach( $items as $item_id => $item )? An order can have multiple items so you can’t rely on $item_id outside of an items loop. It also looks like you want to look at the product ID ($item['product_id']) rather than the item ID. In a separate location you could initiate your own (code assumes this is below the actual items list in the invoice):

    
    <?php
    foreach( $items as $item_id => $item ) {
    	switch ($item_id) {
    		case 16:
    			echo '<img src="https://example.com/wp-content/uploads/test1.png" />';
    			break;
    		case 17:
    			echo '<img src="https://example.com/wp-content/uploads/test2.png" />';
    			break;
    		default:
    			// for debugging only:
    			echo "not a known item: {$item['product_id']}"
    			break;
    	}
    }
    ?>
    

    As a simple first check (that assumes your orders are always only one product) you could also us $item['product_id'] instead of $item_id in your original code.

    By the way I strongly recommend using server paths rather than URLs, which is more reliable and much faster that loading it over the internet:

    
    printf( '<img src="%s/uploads/test2.png" />', untrailingslashit( WP_CONTENT_DIR ) );
    

    Let us know if that helps!
    Ewout

    Thread Starter andyzz8

    (@andyzz)

    Thank you so much @pomegranate @kluver

    I used:

    <?php
    if( $item['product_id'] == '16' ) {
                printf( '<img src="%s/uploads/test1.png" />', untrailingslashit( WP_CONTENT_DIR ) );
    }
    ?>
    
    <?php
    if( $item['product_id'] == '17' ) {
                printf( '<img src="%s/uploads/test2.png" />', untrailingslashit( WP_CONTENT_DIR ) );
    }
    ?>

    There might be a better way of doing this but it seems to work for now!
    At some point I will need to figure out how to add product specific text too.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Add a variable image at the bottom of the invioce’ is closed to new replies.