woocommerce_thankyou hook not working

后端 未结 1 1071
忘掉有多难
忘掉有多难 2020-12-10 10:42

When I paste the code below directly into the thankyou.php, it works perfectly fine. but when I try to hook it into woocommerce_thankyou, nothing h

相关标签:
1条回答
  • 2020-12-10 10:48

    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";
        }
    }
    

    Hope this helps!

    0 讨论(0)
提交回复
热议问题