我的客戶希望能夠將PayPal加載到購物車按鈕放置在頁面的任何位置,並且可能在單個頁面上有多個按鈕。他將使用[MONKEY]價格之類的短代碼,以PaylPal按鈕替換該文本,並附上「猴子」的價格和描述。在頁面上多次用HTML替換shortcode
因此,每當我們在頁面上找到[價格]簡碼時,我需要查詢數據庫以獲取價值,然後插入以下PayPal按鈕代碼,並在頁面上的該位置顯示按鈕。然後移動到下一個替換品,如果有的話。
這裏的PayPal按鈕代碼:
<form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" value="_cart" name="cmd" />
<input type="hidden" value="[email protected]" name="business" />
<input type="hidden" value="1" name="add" />
<input type="hidden" value="MONKEY" name="item_name" />
<input type="hidden" value="" name="item_number" />
<input type="hidden" value="17.00" name="amount" />
<input type="hidden" value="2" name="no_shipping" />
<input type="hidden" value="USD" name="currency_code" />
<input border="0" type="image" name="submit" src="https://www.paypal.com/en_US/i/btn/x-click-but22.gif" alt="Make payments with PayPal - it's fast, free and secure!" />
</form>
我一直在試圖用preg_replace_callback()函數來做到這一點,但有將所有的HTML按鈕的問題,然後尋找更多的簡碼實例在頁面上並替換它們。
感謝您的幫助!在Wordpress中,所有這些代碼都已經寫好了(但在哪裏?) - 這是我從頭開始創建的應用程序,現在需要一些改進。謝謝!
這裏是我的正則表達式:
$pattern = '/\[price (.*?)\]/';
你可以顯示你的正則表達式嗎? –
$ pattern ='/ \ [price(。*?)\] /'; –
好吧..當我粘貼上述消息時,反斜槓消失了。 –