将订单标记为已完成时,处理WooCommerce预购付款

时间:2020-09-01 15:05:52

标签: wordpress woocommerce preorder

仅当我们的预激活商品退出仓库时,我才尝试向WooCommerce中的客户收费。

为此,我将 Moneris付款网关插件 WooCommerce Pre-Order插件一起使用,该令牌将安全存储付款信息的令牌化。我需要手动进入插件的预购信息中心以完成订单,然后再处理费用。当物品离开仓库时,我们会手动执行此操作。

要主动执行我们的履行流程,我们希望使用一个集成,该集成可以简单地在WooCommerce和我们的系统之间进行连接,并在退出仓库时将订单状态切换为完成。

问题在于, WooCommerce预购插件不会在订单切换为完成后向客户信用卡收费,因此需要先在其预购仪表盘中进行处理。< / p>

在查看了他们的documentation之后,似乎可以通过以下操作来处理预订付款...

add_action( 'wc_pre_orders_process_pre_order_completion_payment_' . $this->id, array( $this, 'process_pre_order_payments' ) );

现在,我想知道是否最好在我的functions.php中添加一个代码片段,以便每次在WooCommerce中具有完整状态的订单时都调用“ wc_pre_orders_process_pre_order_completion_payment_”,而不是直接修改插件代码。

也许这样可以工作:

/********************************************************************************
***    Woocommerce charge preorder when order status change to completed      ***
*********************************************************************************/
function mysite_woocommerce_order_status_completed( $order_id ) { 

// success!
  if ( $transaction_successful ) {

// the total amount to charge is the the order's total
    $total = $order->get_total();

// complete the order
    $order->process_pre_order_payments();
  } 

  else{
    echo "not working";
  }

}
add_action( 'woocommerce_order_status_completed', 'mysite_woocommerce_order_status_completed', 10, 1 );

0 个答案:

没有答案