2017-07-15 33 views
0
add_action('woocommerce_single_product_summary', 'whatsappdirect1', 35); 

function whatsappdirect1() { 
    echo '[anchor-tag a class="btn btn-social-icon btn-whatsapp" href="javascript:window.location=waCurrentPage();">[img tag border="0" alt="W3Schools" src="http://sareechoice.com/wp-content/uploads/2017/07/whatsappicon.png" width="290" height="200"][anchor-tag-closed]'; 
} 

[script] 
waCurrentPage = function() { 
    return encodeURI("whatsapp://send?phone=+9199999999&text=please let me know the price of the product in the link : " + 'http://' + window.location.hostname + window.location.pathname); 
} 
[/script] 

我已經提出了以下代碼,允許移動用戶在我的網站上聯繫我的支持團隊以及我的whatsapp連同頁面的鏈接。在上面的add_action代碼中,我已經放置了代碼,這將顯示我的按鈕,該按鈕必須在woocommerce產品頁面上單擊。如何在wocommerce add_action中添加腳本標籤編碼?

但現在的問題是,腳本代碼做了實際的工作,打開我的whatsapp數字預定鏈接,允許用戶發送到我的號碼。

那麼如何插入腳本代碼以及在哪裏插入呢?有什麼辦法,我可以在兩個代碼保持一個add_action wooocommerce功能?

+0

1.停止使用過量分,你怎麼也想不到catastrophal它看起來。 2.無論如何,至少遵循[這些非常基本的規則](https://meta.stackoverflow.com/a/291370/1783163)將非常有用。 – peterh

+0

看,你現在的問題有多美麗。 – peterh

回答

0

試試這個功能如下

add_action('woocommerce_single_product_summary', 'whatsappdirect1', 35); 

    function whatsappdirect1() { 
     echo '<a class="btn btn-social-icon btn-whatsapp" href="javascript:window.location=waCurrentPage();"><img border="0" alt="W3Schools" src="http://sareechoice.com/wp-content/uploads/2017/07/whatsappicon.png" width="290" height="200"/></a>'; 
     echo '<script type="text/javascript"> 
    waCurrentPage = function() { 
     return encodeURI("whatsapp://send?phone=+9199999999&text=please let me know the price of the product in the link : " + "http://" + window.location.hostname + window.location.pathname); 
    } 
    </script>'; 
    } 
+0

謝謝你的答案..但這是顯示錯誤 – Moin

+0

請分享你的錯誤。 –

+0

嗨表達式,它得到了解決,感謝您的幫助..實際上一個單獨的腳本需要寫入JavaScript文件,然後我們可以從woocommerce代碼調用該功能...感謝您的幫助 – Moin