Customize product template, add product variation near sku

This topic has 10 replies, 2 voices, and was last updated 5 months ago ago by Luca Rossi

  • Avatar: Mauro Giorgi
    M.
    Participant
    July 14, 2025 at 09:51

    Hi, is possible add single product variation near sku into product template?
    See private content for details..
    Thanks

    Please, contact administrator
    for this information.
    9 Answers
    Avatar: Justin
    Luca Rossi
    Support staff
    July 14, 2025 at 17:20

    Dear @M.,

    We hope this message finds you well.

    We are still unclear about certain aspects of your website. Could you kindly provide more detailed information or share any relevant images or videos that might help us better understand the issue?

    Thank you in advance for your cooperation.

    Best regards,
    The 8Theme Team

    Avatar: Mauro Giorgi
    M.
    Participant
    July 14, 2025 at 17:24

    I want add specific product attribute near SKU

    Please contact administrator
    for this information.
    Avatar: Justin
    Luca Rossi
    Support staff
    July 15, 2025 at 06:36

    Dear @M.,

    We hope this message finds you well.

    To display the manufacturer code below the SKU element, you can create a custom shortcode as follows:

    
    add_shortcode( 'codice_produttore', 'shortcode_codice_produttore' );
    function shortcode_codice_produttore() {
        $attribute_value = wc_get_product()->get_attribute('pa_codice_produttore');
        if ( $attribute_value ) {
            echo 'Attribute: ' . esc_html( $attribute_value );
        }
    }
    

    Once the shortcode [codice_produttore] is created, you may insert it directly below the SKU element in your template.

    Should you need any further assistance, please do not hesitate to contact us.

    Best regards,
    The 8Theme Team

    Avatar: Mauro Giorgi
    M.
    Participant
    July 15, 2025 at 07:38

    I’ve added this code:

    add_shortcode( ‘codice_produttore’, ‘shortcode_codice_produttore’ );
    function shortcode_codice_produttore() {
    $attribute_value = wc_get_product()->get_attribute(‘codice-produttore’);
    if ( $attribute_value ) {
    echo ‘Code: ‘ . esc_html( $attribute_value );
    }
    }

    But this print all products attributes, il possible display only the attribute of selected variation?

    Thanks

    Please contact administrator
    for this information.
    Avatar: Justin
    Luca Rossi
    Support staff
    July 15, 2025 at 08:51

    Hi @M.

    Can you please try with this code instead?

    
    add_shortcode( 'codice_produttore', 'shortcode_codice_produttore' );
    
    function shortcode_codice_produttore() {
        global $product;
        
        // If no global product, try to get current product
        if ( ! $product ) {
            global $post;
            if ( $post && $post->post_type === 'product' ) {
                $product = wc_get_product( $post->ID );
            }
        }
        
        // Return empty if no product found
        if ( ! $product ) {
            return '';
        }
        
        // Get attribute value for both simple and variation products
        $attribute_value = $product->get_attribute( 'codice-produttore' );
        
        // If it's a variation and no attribute found, try parent product
        if ( ! $attribute_value && $product->is_type( 'variation' ) ) {
            $parent_product = wc_get_product( $product->get_parent_id() );
            if ( $parent_product ) {
                $attribute_value = $parent_product->get_attribute( 'codice-produttore' );
            }
        }
        
        // Return the attribute value if found
        if ( $attribute_value ) {
            return 'Code: ' . esc_html( $attribute_value );
        }
        
        return '';
    }
    

    Let us know how it goes!

    Avatar: Mauro Giorgi
    M.
    Participant
    July 15, 2025 at 08:56

    Same result… I see all variations code.
    I think i’ve to add javascript code in order to update value if click on variations (like SKU), right?

    Avatar: Justin
    Luca Rossi
    Support staff
    July 15, 2025 at 10:17

    Dear @M.,

    We hope this message finds you well.

    Regarding your request related to JavaScript, you may consider using the following custom script:

    
    jQuery(function($){
        $('form.cart').on('show_variation', function(event, data) {
            console.log(data);
        });
    });
    

    We hope this proves helpful. Should you have any further questions or require additional assistance, please do not hesitate to reach out.

    Best regards,
    The 8Theme Team

    Avatar: Mauro Giorgi
    M.
    Participant
    July 15, 2025 at 11:03

    I can’t obtain right code, if I send FTP credential and WP admin access can you help me?
    My goal il put ‘codice-produttore’ near SKU and update when update variations like SKU value
    Thanks

    Avatar: Justin
    Luca Rossi
    Support staff
    July 16, 2025 at 04:54

    Hi @M.,

    Could you please provide the FTP account details and WordPress admin access so that we can review the issue and determine what assistance we can offer?

    Please note that, as this request falls outside the scope of our standard support policy, we cannot guarantee a 100% resolution. However, we will do our best to help.

    Best regards,
    The 8Theme Team

  • Viewing 10 results - 1 through 10 (of 10 total)

You must be logged in to reply to this topic.Log in/Sign up

We're using our own and third-party cookies to improve your experience and our website. Keep on browsing to accept our cookie policy.