Divi WordPress Theme
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

WordPress fix get Variable product SKU in Contact Form 7

Discussion in 'Misc WordPress Requests' started by navdha_y, Jan 2, 2018.

  1. navdha_y


    get Variable product SKU in Contact Form 7, by navdha_y


    I want to attach product SKU in for product variation in Contact Form 7.
    However I am able to get simple product SKU in function.php file , craete shortcode for it & attach it to CF7.
    But not possible with variation sKU.
    Can anyone let me know how I should achieve this?

    Code below for simple SKU is working.

    function custom_get_product_sku( $atts ) {

    global $product;

    $atts = shortcode_atts( array(
    'id' => '',
    ), $atts );

    // If no id, we're probably on a product page already
    if ( empty( $atts['id'] ) ) {

    $sku = $product->get_sku();

    } else {

    //get which product from ID we should display a SKU for
    $product = wc_get_product( $atts['id'] );
    $sku = $product->get_sku();



    //Only echo if there is a SKU
    if ( !empty( $sku ) ) {
    echo $sku;

    return ob_get_clean();

    add_shortcode( 'wc_sku', 'custom_get_product_sku' );

    Help Me ASAP please.

    Thanks in advance!

    get Variable product SKU in Contact Form 7

Share This Page

Monarch Social Sharing Plugin