[Support request] sideheader image woocommerce

Home Forums Support [Support request] sideheader image woocommerce

Home Forums Support sideheader image woocommerce

Viewing 13 posts - 16 through 28 (of 28 total)
  • Author
    Posts
  • #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…

    #622484
    Tom
    Lead Developer
    Lead Developer

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

    #622768
    Nikolaj
    #622784
    David
    Staff
    Customer Support

    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; ?>
    #622790
    Nikolaj

    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

    #622947
    Tom
    Lead Developer
    Lead Developer

    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?

    #622953
    Nikolaj

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

    screenshot

    #623039
    Tom
    Lead Developer
    Lead Developer

    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' ) );
    }
    ?>
    #623044
    Nikolaj

    whambamboogie that did the trick;) THANKS…

    #623048
    Nikolaj

    how to make sure “the legacy Page Header metabox” doesn’t disappear in future updates?

    #623059
    Tom
    Lead Developer
    Lead Developer

    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 🙂

    #623060
    Nikolaj

    sure hit me on the “Custom Fields” 😉 Thanks for always helping…

    #623196
    Tom
    Lead Developer
    Lead Developer

    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' ) );
    }
    ?>
Viewing 13 posts - 16 through 28 (of 28 total)
  • You must be logged in to reply to this topic.