- This topic has 27 replies, 4 voices, and was last updated 7 years, 8 months ago by
Tom.
-
AuthorPosts
-
July 12, 2018 at 1:01 pm #622347
Nikolaj
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…
July 12, 2018 at 7:14 pm #622484Tom
Lead DeveloperLead DeveloperDo you have any example sites you can show me? Just so I understand 100% before guessing with some code 🙂
July 13, 2018 at 5:04 am #622768Nikolaj
July 13, 2018 at 5:42 am #622784David
StaffCustomer SupportYou 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; ?>July 13, 2018 at 5:53 am #622790Nikolaj
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_thumbnailJuly 13, 2018 at 8:22 am #622947Tom
Lead DeveloperLead DeveloperWhat 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?
July 13, 2018 at 8:28 am #622953Nikolaj
yes it’s a metabox within the wc product – I believe it’s from your theme?;)
July 13, 2018 at 10:15 am #623039Tom
Lead DeveloperLead DeveloperAha, 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' ) ); } ?>July 13, 2018 at 10:24 am #623044Nikolaj
whambamboogie that did the trick;) THANKS…
July 13, 2018 at 10:28 am #623048Nikolaj
how to make sure “the legacy Page Header metabox” doesn’t disappear in future updates?
July 13, 2018 at 10:42 am #623059Tom
Lead DeveloperLead DeveloperJust 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 🙂
July 13, 2018 at 10:43 am #623060Nikolaj
sure hit me on the “Custom Fields” 😉 Thanks for always helping…
July 13, 2018 at 2:50 pm #623196Tom
Lead DeveloperLead DeveloperSo 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:
sideheaderThen in the value, enter the ID of the image you want to use:
123Then 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' ) ); } ?> -
AuthorPosts
- You must be logged in to reply to this topic.