• Resolved pas2019

    (@pas2019)


    Hi,

    Hope someone can help me out?

    I am building a new shop with Woocommerce and elementor and i want to display the SKU of a variable product on the product page, i need a shortcode for this. The default shortcode shows the SKU of the parent product wich is not right.

    The SKU needs to change whenever the user changes te dropdown.

    I found the code below but i need a shortcode instead.
    The code below adds the right sku on the variable product description.

    add_action('woocommerce_single_product_summary', 'display_product_sku_and_gtin', );
    function display_product_sku_and_gtin() {
        global $product; 
    
        echo '<p>' . __("SKU:") . ' ' . $product->get_sku() . '</p>';
    
        if( get_post_meta( $product->get_id(), 'barcode', true) )
            echo '<p>' . __("GTIN:") . ' ' . get_post_meta( $product->get_id(), 'barcode', true) . '</p>';                  
    }
    // Display product variations SKU and GTIN info
    add_filter( 'woocommerce_available_variation', 'display_variation_sku_and_gtin', 20, 3 );
    function display_variation_sku_and_gtin( $variation_data, $product, $variation ) {
        $html = ''; // Initializing
    
        // Inserting SKU
        if( ! empty( $variation_data['sku'] ) ){
            $html .= '</div><div class="woocommerce-variation-sku">' . __('SKU:') . ' ' . $variation_data['sku'];
        }
    
        // Inserting GTIN
        if( get_post_meta( $variation->get_id(), 'barcode', true ) ){
            $gtin = get_post_meta( $variation->get_id(), 'barcode', true );
            $html .= '</div><div class="woocommerce-variation-gtin">' . __('GTIN:') . ' ' . $gtin;
        }
    
        // Using the variation description to add dynamically the SKU and the GTIN
        $variation_data['variation_description'] .= $html;
    
        return $variation_data;
    }
Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support Gabriel – a11n

    (@gabrielfuentes)

    Hi there ??

    This is a fairly complex development topic. I’m going to leave it open for a bit to see if anyone is able to chime in to help you out.

    I can also recommend the WooCommerce Developer Resources Portal for resources on developing for WooCommerce.

    You can also visit the WooCommerce Facebook group or the #developers channel of the WooCommerce Community Slack. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.

    If you do require more help with the actual coding, we’d recommend you hire a developer who can take a look at this, quote you for their services and help you add this feature to your site. We’d recommend getting in touch with a web developer or one of the customisation experts listed at https://woocommerce.com/customizations/.

    Cheers.

    Anonymous User 12905264

    (@anonymized-12905264)

    Hello!

    Any news on this?

    I am trying to achieve the same thing and sadly have not figured it out.

    Adrien Flüeler

    (@adrienwebsitecreation)

    Hi guys,
    Are you using elementor Pro or the free version?

    I am somewhat in a similar situation; building a website with woocommerce and using elementor to create custom product page.

    I do not need to have the SKU to change (this is not what I try to achieve); but I am trying to have the dropdown of the variation to show under the quantity dropdown.

    Any idea of how to achive that?

    Thanks for the help.

    Mirko P.

    (@rainfallnixfig)

    Hi there!

    It looks like there has no been much activity on this thread so I recommend trying the above resources for developers shared by my colleague. If you get to find the correct solution please post it here so it can help also others having the same requirements.

    Thanks.

    Looking for a solution as well ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Woocommerce shortcode to display variation SKU’ is closed to new replies.