2017-07-26 151 views
3

沿着這post的線,我試圖連接到我自己的定製支付網關網關。WooCommerce 3.0:當管理員使用我的付款通過管理面板創建一個訂單找不到鉤相當於管理員創建後端訂單

我加入以下代碼:

add_action('woocommerce_process_shop_order_meta', array($this, 'process_offline_order')); 
    add_action('woocommerce_admin_order_actions_end', array($this, 'process_offline_order2')); 
    add_action('woocommerce_save_post_shop_order', array($this, 'process_offline_order3')); 

我曾嘗試在Xdebug的breakp點下降到這些相應的方法,但他們都不擊中。

+0

究竟是什麼問題呢?你想做什麼? – Reigel

+0

你的問題到底是什麼? –

+0

我試圖觸發它可以連接到支付網關API當WooCommerce管理員創建代表其客戶之一的秩序的事件。 – Pro777

回答

1

一些研究和測試後,我認爲爲正確的鉤子是這樣的WP掛鉤之一:

所以我已經使用了第一個,因爲它是最方便的「shop_order「後類型:

add_action('save_post_shop_order', 'process_offline_order', 10, 3); 
function process_offline_order($post_id, $post, $update){ 

    // Orders in backend only 
    if(! is_admin()) return; 

    // Get an instance of the WC_Order object (in a plugin) 
    $order = new WC_Order($post_id); 

    // For testing purpose 
    $trigger_status = get_post_meta($post_id, '_hook_is_triggered', true); 

    // 1. Fired the first time you hit create a new order (before saving it) 
    if(! $update) 
     update_post_meta($post_id, '_hook_is_triggered', 'Create new order'); // Testing 

    if($update){ 
     // 2. Fired when saving a new order 
     if('Create new order' == $trigger_status){ 
      update_post_meta($post_id, '_hook_is_triggered', 'Save the new order'); // Testing 
     } 
     // 3. Fired when Updating an order 
     else{ 
      update_post_meta($post_id, '_hook_is_triggered', 'Update order'); // Testing 
     } 
    } 
} 

您將能夠與此代碼輕鬆地測試。對我來說它工作正常。


我還與woocommerce_before_order_object_save鉤試圖具有2個參數:

  • $order(所述WC_Order對象)
  • $data_store(數據通過WC_Data_Store類被存儲)

但我沒有得到它的工作,因爲我所期待的。我已經在WC_Ordersave()方法的源代碼中發現它。

+1

這段代碼看起來很完美,但我無法獲得該方法來觸發本地或我的測試服務器。我想這可能是我的配置。 – Pro777