woocommerce_thankyou 钩子不工作
woocommerce_thankyou hook not working
当我将下面的代码直接粘贴到 thankyou.php
时,它工作得很好。但是当我尝试将它连接到 woocommerce_thankyou
时,没有任何反应。
我刚开始 PHP,
add_action('woocommerce_thankyou', 'test_1', 10, 1);
function test_1() {
$paymethod = $order->payment_method_title;
$orderstat = $order->get_status();
if (($orderstat == 'completed') && ($paymethod == 'PayPal')) {
echo "something";
} elseif (($orderstat == 'processing') && ($paymethod == 'PayPal')) {
echo "some other shit";
} elseif (($orderstat == 'pending') && ($paymethod == 'PayPal')) {
echo "some other shit";
}
}
First of all you have to add the function and hook in functions.php
file of your active child theme (or theme). Or also in any plugin PHP
files. Secondly you need to create an instance/object of order, to
access the data.
add_action('woocommerce_thankyou', 'wh_test_1', 10, 1);
function wh_test_1($order_id) { //<--check this line
//create an order instance
$order = wc_get_order($order_id); //<--check this line
$paymethod = $order->payment_method_title;
$orderstat = $order->get_status();
if (($orderstat == 'completed') && ($paymethod == 'PayPal')) {
echo "something";
}
elseif (($orderstat == 'processing') && ($paymethod == 'PayPal')) {
echo "some other code";
}
elseif (($orderstat == 'pending') && ($paymethod == 'PayPal')) {
echo "some other code";
}
}
希望对您有所帮助!
当我将下面的代码直接粘贴到 thankyou.php
时,它工作得很好。但是当我尝试将它连接到 woocommerce_thankyou
时,没有任何反应。
我刚开始 PHP,
add_action('woocommerce_thankyou', 'test_1', 10, 1);
function test_1() {
$paymethod = $order->payment_method_title;
$orderstat = $order->get_status();
if (($orderstat == 'completed') && ($paymethod == 'PayPal')) {
echo "something";
} elseif (($orderstat == 'processing') && ($paymethod == 'PayPal')) {
echo "some other shit";
} elseif (($orderstat == 'pending') && ($paymethod == 'PayPal')) {
echo "some other shit";
}
}
First of all you have to add the function and hook in
functions.php
file of your active child theme (or theme). Or also in any plugin PHP files. Secondly you need to create an instance/object of order, to access the data.
add_action('woocommerce_thankyou', 'wh_test_1', 10, 1);
function wh_test_1($order_id) { //<--check this line
//create an order instance
$order = wc_get_order($order_id); //<--check this line
$paymethod = $order->payment_method_title;
$orderstat = $order->get_status();
if (($orderstat == 'completed') && ($paymethod == 'PayPal')) {
echo "something";
}
elseif (($orderstat == 'processing') && ($paymethod == 'PayPal')) {
echo "some other code";
}
elseif (($orderstat == 'pending') && ($paymethod == 'PayPal')) {
echo "some other code";
}
}
希望对您有所帮助!