dryl34156 2019-02-16 02:16
浏览 91

woocommerce_order_status_completed没有调用条纹付款

I have written a custom plugin and part of this plug in uses the "woocommerce_order_status_completed" hook as:

add_action( 'woocommerce_order_status_completed', 'mmd_woointerface_order_complete', 1);
mmd_woointerface_order_complete($order)
{
 //print to log file here
}

I am using the stripe payment system and have checked and double checked the API Keys, have defined the Webhook end points as recommended by the woocommerce plugins.

  1. I tried making a purchase and the system seem to respond correctly, with orders showing up in the backend of my site.
  2. I have tried sending test webhooks using the strip backend.

None of these options cause the mmd_woointerface_order_complete, action to performed. My custom call is never initiated. Am I missing something.

Has any one got this to work with Stripe? Need help.

  • 写回答

1条回答 默认 最新

  • douba4275 2019-02-22 00:06
    关注

    PROBLEM SOLVED! If you use stripe and want to write code that gets called upon a payment. The woocommerce stripe plugin has a whole other action hook sdk.

    You can find the link to the calls here: https://docs.woocommerce.com/document/stripe/#section-13

    The one that works best, but different from the standard woocommerce hooks is "wc_gateway_stripe_process_response ($stripe_response, $order)"

    You will need to check the $stripe-response variable which is assigned one of the following string values:'succeeded', 'failed', 'pending', and 'on-hold'

    This is the code I wrote and it works remarkably well.

    function ProcessStripePayment($stripe_response, $order)
      {
        switch($stripe_response->status)
        {
        case 'succeeded';
           DebugLog('wc_gateway_stripe_process_payment HOOK FIRED  succeeded'); 
        break;
    
        case 'failed';
         DebugLog('wc_gateway_stripe_process_payment HOOK FIRED - failed'); 
        break;
    
        case 'pending';
            DebugLog('wc_gateway_stripe_process_payment HOOK FIRED - pending'); 
        break;
    
        case 'on-hold';
           DebugLog('wc_gateway_stripe_process_payment HOOK FIRED - on-hold');  
        break;          
        }   
      }
    

    The other rather LARGE gotcha, is, as of now, this does not work in a plugin. You have to put it in function.php OR I used a plugin called snippets. That does the job.

    The rest of the code you need to write is a off-take of the class structure.

    $order               = new WC_Order( $order_id ); 
    

    Pretty straight forward until you get to Meta_data, which is used by the woocommerce checkout fields. For that this works:

    foreach($MetaData as $SubRow)
     {
     switch($SubRow->key)
       {
        case 'Your Custom Field Name':
        break;
       } // switch($SubRow->key) 
    
    DebugLog($SubRow->key); 
    DebugLog($SubRow->value);       
    }   // foreach($MetaData as $SubRow)
    
    评论

报告相同问题?

悬赏问题

  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题