woocommerce_thankyou 被调用了 4 次 [英] woocommerce_thankyou get's called 4 times
问题描述
我们正在使用 woocommerce_thankyou 在结帐时执行操作.但是,在一个简单的测试中,如果我设置了动作并且只是echo 'Test';"它发生了 4 次.这是代码
We are using woocommerce_thankyou to execute an action on checkout. However, in a simple test, if I set the action and just "echo 'Test';" it happens 4 times. This is the code
class OrderController
{
public function __construct()
{
add_action('woocommerce_thankyou', array($this, 'orderSubmit'));
}
function orderSubmit()
{
global $woocommerce;
echo "test"; // happens 4 times
}
}
推荐答案
我今天早些时候遇到了同样的问题.
I was experiencing the same issue earlier today.
我进入服务器文件查看器(或本地主机)并进入 wp-content/plugins/woocommerce/templates/checkout
I went into server file viewer (or local host) and went to wp-content/plugins/woocommerce/templates/checkout
在 checkout 文件夹中有一个名为thankyou.php 的 php 文件.
Inside the checkout folder there is a php file called thankyou.php.
在第 65 行左右会有代码说
Around line 65 or so there will be code that says
<?php do_action( 'woocommerce_thankyou' . $order->payment_method, $order->id ); ?>
或类似的东西
我的问题是它有 2 个这样的动作执行.
The issue in mine is that it had 2 of these action executions.
摆脱除一个之外的所有这些,这应该可以解决您的问题.
Get rid of all them except one and this should fix your problem.
请务必在之后测试您的 woocommerce 以确保您没有删除错误的内容
Be sure to test your woocommerce afterwards to ensure you didn't delete the wrong one
这篇关于woocommerce_thankyou 被调用了 4 次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!