I have a product with a few variations that need to show a shortcode that returns a date in format Month-YYYY: [prox_meses="1"].
After googling a bit I managed to allow shortcodes in the single product page, inside the variations dropdown using the following code:
// Single product page
function display_shortcode_in_variation_names( $term, $term_obj ) {
$product = wc_get_product();
$id = $product->get_id();
if ( empty( $term ) || empty( $id ) ) {
return $term;
}
if ( $product->is_type( 'variable' ) ) {
$product_variations = $product->get_available_variations();
} else {
return $term;
}
foreach ( $product_variations as $variation ) {
if ( count( $variation['attributes'] ) > 1 ) {
return $term;
}
$attribute = array_values( $variation['attributes'] )[0];
if ( $attribute === $term_obj->slug ) {
$term = do_shortcode($term);
}
}
return $term;
}
add_filter( 'woocommerce_variation_option_name', 'display_shortcode_in_variation_names', 10, 2 );
But the shortcode isn't working in the Cart, Checkout or Order information. I'm not sure how to get that working.