I would like to use a pods shortcode field inside the woocommerce variable product description but by default the variable description field does not support shortcodes.
The variation description is stored in an array woocommerce_available_variation, so I can't simple call the function do_shortcode($variation).
I am trying to allow short codes in this field by using the below code:
add_filter( 'woocommerce_available_variation', 'shortcode_variation_description');
function shortcode_variation_description( $variation ) {
$variation['variation_description'] = do_shortcode( $variation['variation_description'] );
return $variation;
But it's not working. Why?
When using your code, it works. To test, I have used the Woocommerce shortcode [products]
in a variation description as follow:
The imputed text is (where 37
is a real simple product ID):
"This is a description with a shortcode… [products ids="37"] As you can see this shorcode is detected and displayed."
And I get this display:
So it works for real. I have lightly made some little changes to this code version (yours work too):
add_filter( 'woocommerce_available_variation', 'variation_description_allow_shortcodes', 10, 3 );
function variation_description_allow_shortcodes( $variation_data, $product, $variation ) {
$variation_data['variation_description'] = do_shortcode( $variation_data['variation_description'] );
return $variation_data;
}
Code goes in function.php file of your active child theme (active theme). Tested and works.