Walter Fury
Walter Fury

Reputation: 1

Add a shortcode above the WooCommerce product short description

I am trying to add a shortcode to all my woocommerce single product pages. I want the shortcode to appear above the short description.

I have found this code and added it to functions.php, but I can see that it adds the shortcode below the short description (and above the add to cart button).

add_filter('woocommerce_short_description','ts_add_text_short_descr');
function ts_add_text_short_descr($description){
   $text = do_shortcode('[my-shortcode]');
  return $description.$text;
}

I would be very gratefull for some help :)

Upvotes: 0

Views: 1149

Answers (2)

Bhautik
Bhautik

Reputation: 11282

You can use the woocommerce_single_product_summary action hook. try the below code. The code will go in your active theme functions.php file.

function add_shortcode_before_short_description(){
    echo do_shortcode( '[wpqr-code]' );
}
add_action( 'woocommerce_single_product_summary', 'add_shortcode_before_short_description', 15, 1 );

Tested and works

enter image description here

Upvotes: 2

Manish Pushkar Jha
Manish Pushkar Jha

Reputation: 138

function customShortcodeBeforeShortDescription( $post_excerpt ) 
{
    echo do_shortcode('[wpqr-code]');    
}
add_filter('woocommerce_short_description','customShortcodeBeforeShortDescription', 10, 1);

Upvotes: 1

Related Questions