get Variable product SKU in Contact Form 7
-
Hello,
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(); } ob_start(); //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!
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘get Variable product SKU in Contact Form 7’ is closed to new replies.