skip to Main Content

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 🙂

2

Answers


  1. function customShortcodeBeforeShortDescription( $post_excerpt ) 
    {
        echo do_shortcode('[wpqr-code]');    
    }
    add_filter('woocommerce_short_description','customShortcodeBeforeShortDescription', 10, 1);
    
    Login or Signup to reply.
  2. 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search