Site logo

Archived topic

sideheader image woocommerce

27 replies · Started by Nikolaj on July 10, 2018

Viewing posts 16–28 of 28

adding this to the single-product.php will show the product image on top. But I need to show the sideheader image:

<?php 
    $test = new WC_Product($product_ID);
    echo "<div class='kampagneBillede' >".$test->get_image();  "</div>"   
?>

cheers...

Do you have any example sites you can show me? Just so I understand 100% before guessing with some code :)

You could use GP Hooks with this:

<?php if ( is_product() && has_post_thumbnail( $post->ID ) ):
	echo get_the_post_thumbnail( $post_id, 'full', array( 'class' => 'aligncenter' ) );
endif; ?>

thanks but it need to be the url from the assigned sideheader / image that has to be shown not the thumbnail so this should reference the sideheader image instead of thumbnail: get_the_post_thumbnail

What exactly is the sideheader? Is it a metabox named "sideheader" while editing your products? If so, is it being added by a specific plugin? Custom function?

yes it's a metabox within the wc product - I believe it's from your theme?;)

screenshot

Aha, you're using the legacy Page Header metabox.

In that case, you should be able to do this:

<?php
$custom_image = get_post_meta( get_the_ID(), '_meta-generate-page-header-image-id', true );

if ( function_exists( 'is_product' ) && is_product() && $custom_image ) {
	echo wp_get_attachment_image( $custom_image, 'full', array( 'class' => 'aligncenter' ) );
}
?>

whambamboogie that did the trick;) THANKS...

how to make sure "the legacy Page Header metabox" doesn't disappear in future updates?

Just keep the Page Header module activated.

The Page Header module is being deprecated in 1.7, but it won't disappear.

A better solution would be to use the "Custom Fields" metabox in WordPress. Let me know if you'd prefer that method :)

sure hit me on the “Custom Fields” ;) Thanks for always helping...

So you can enable Custom Fields by clicking "Screen Options" at the top right of the edit area, and checking the "Custom Fields" checkbox.

Then add a new Custom Field, and give it a name like: sideheader

Then in the value, enter the ID of the image you want to use: 123

Then your code would be:

<?php
$custom_image = get_post_meta( get_the_ID(), 'sideheader', true );

if ( function_exists( 'is_product' ) && is_product() && $custom_image ) {
	echo wp_get_attachment_image( $custom_image, 'full', array( 'class' => 'aligncenter' ) );
}
?>
This archived topic is closed to new replies.