Sj03rs
Sj03rs

Reputation: 937

Woocommerce add shortcode to front-end product page

I have been learning on how to make a plugin for Wordpress.
Now I am stumbling upon a "problem".
Which is: I need to add my shortcode to the product page of Woocommerce.

I have this function which makes my shortcode:

function ws_frontend_product_page_validate() {

    // no actual validation yet
    $output = ws_frontend_product_page();
    return $output;

}
add_shortcode('ws_frame', 'ws_frontend_product_page_validate');
function ws_frontend_product_page() {

    ?>

        <iframe src="http://www.example.com/" style="width: 100%; height: 100%;" scrolling="no" frameBorder="0"></iframe>

    <?php

}

So how can I add [ws_frame] to the Woocommerce product pages?
I haven't found any tutorials as of how I can implement this into Woocommerce product pages.
I have found it very difficult to find the tutorials that I need to develope a plugin for Woocommerce.
Any suggested tutorials would be very nice!

UPDATE

Now I have got an answer of Piyush Dhanotiya. I have yet to get the position right.

If I use the code of Piyush Dhanotiya it shows up as this:

enter image description here

Yet, I want it here:

enter image description here

Upvotes: 0

Views: 5627

Answers (1)

Piyush Dhanotiya
Piyush Dhanotiya

Reputation: 579

add_shortcode('ws_frame', 'ws_frontend_product_page_validate');
function ws_frontend_product_page_validate() {

   echo '<iframe src="http://www.example.com/" style="width: 100%; height: 100%;" scrolling="no" frameBorder="0"></iframe>';

}

add_action( 'woocommerce_after_main_content', 'action_woocommerce_after_main_content', 10);

function action_woocommerce_after_main_content(){


    do_shortcode('[ws_frame]');
}

Upvotes: 2

Related Questions