首页 文章

Woocommerce将短代码添加到前端产品页面

提问于
浏览
0

我一直在学习如何为Wordpress制作一个插件 .
现在我绊倒了"problem" .
这是:我需要将我的短代码添加到 Woocommerce 的产品页面 .

我有这个函数,它使我的短代码:

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

}

那么如何将 [ws_frame] 添加到Woocommerce产品页面?
我没有找到任何关于如何将其实现到Woocommerce产品页面的教程 .
我发现很难找到开发Woocommerce插件所需的教程 .
任何建议的教程都会非常好!

UPDATE

现在我得到了Piyush Dhanotiya的答案 . 我还没有得到正确的立场 .

如果我使用Piyush Dhanotiya的代码,它会显示为:

enter image description here

但是,我想在这里:

enter image description here

1 回答

  • 2
    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]');
    }
    

相关问题