将PayPal“捐赠”按钮链接到Wordpress“发表评论”按钮

时间:2012-05-04 15:17:11

标签: php html wordpress paypal

我正在使用Wordpress模板作为收集口头出价的系统,真正发表评论,这将使网站访问者花费1美元。我已将帖子末尾的标准“发表评论”文字更改为“提交出价”。

我还安装了一个PayPal捐赠插件,在页面上显示“捐赠”按钮。

我想将这两个按钮的功能合并为一个按钮,即“提交出价”按钮。要清楚,“提交出价”按钮会将用户的评论发布到帖子页面;我需要一个按钮来执行此操作,同时指导用户向PayPal捐赠$ 1。

理想情况下,我会检查用户是否确实支付了1美元以便提交出价,但由于这更复杂,并且因为这是出于慈善目的,所以我坚信在我的用户实际支付。捐赠后,PayPal会将其重定向到他们提交口头报价的页面(“评论”)。

“提交出价”按钮的php看起来像是(它来自典型wordpress博客的标准“comments.php”):

<input type="submit" value="Submit Bid" /><input type="hidden" name="comment_post_ID" value="<?php echo $id; ?>" />

PayPal“捐赠”按钮是一个实际放置在页面上的插件:

<?php echo Paypal_payment_accept(); ?>

功能代码很长,但在页面上放置实际“捐赠”按钮的代码是:

$output .= "<input type=\"image\" src=\"$payment_button\" name=\"submit\" alt=\"Make payments with payPal - it's fast, free and secure!\" />";

非常感谢如何解决这个看似微不足道的问题的想法!

2 个答案:

答案 0 :(得分:1)

实际上,可能有一种更简单的方法,而不是使用表单的Paypal提交。

保留重定向代码,但将$ location变量编辑为将用户带到paypal的URL,以及要发送给他们的所有变量, 例如: https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=email%40paypalhacks%2Ecom&amount=1%2E00&currency_code=USD&item_name=donation&item_number=1001&quantity=1&shipping=3%2E00&no_shipping=0

因此它会正常处理评论,然后将用户发送到paypal页面进行付款。您可以在浏览器中转到该URL以检查其是否有效。可能还会添加一个“返回”变量,将用户重新发送回原来的$ location值,这样用户就可以在成功付款到paypal后进入评论页面。

答案 1 :(得分:0)

你基本上想要一个按钮来执行2个动作。因此,为什么不在评论处理代码之前或之后添加paypal重定向功能,而不是有两种形式(paypal插件将添加自己的表单标签)?

因此,当用户按下评论的提交按钮时,让页面正常处理提交,但在该文件中,在处理评论后,将用户重定向到paypal。

您可以更改wp-comments-post.php文件中的代码,该文件位于根Wordpress文件夹中。

你不需要使用插件,这是一个非常简单的paypal代码:

<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="<!-- paypal user email which receives payments -->">
<input type="hidden" name="lc" value="CA">
<input type="hidden" name="item_name" value="<!-- donation -->">
<input type="hidden" name="item_number" value="1">
<input type="hidden" name="amount" value="<!-- donation amount -->">
<input type="hidden" name="currency_code" value="CAD">
<input type="hidden" name="return" value="<!-- the URL to redirect the user after payment -->">
<input type="hidden" name="button_subtype" value="services">
<input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynowCC_LG.gif:NonHosted">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
                <img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1"><br />
            </form>

此外,您可以审核所有评论,因此在主持人批准之前,这些评论不会在网站上发布。您可以在信息中心&gt;中管理这些设置。设置&gt;讨论。这样,您可以选择仅为通过paypal成功付款的用户(通过比较他们的电子邮件ID)批准评论。