我知道我有一个具体的问题,所以我在搜索了几天后才回答。
Woocommerce拥有its own query 我决定重新使用:
public function pending_orders(){
$query = array(
\'status\' => \'on-hold\',
\'limit\'=>-1
);
$pending_orders = wc_get_orders( $query );
$found_variables = array();
foreach ($pending_orders as $order){
$foundit = array(
\'id\' => $order->id,
\'number\' => trim( str_replace( \'#\', \'\', $order->get_order_number() ) )
);
array_push($found_variables,$foundit);
}
return $found_variables;
}
以上内容将向两者推送相同的数字
\'id\'
和
\'number\'
“我的”列
$found_variables
如果它应用订单号==订单ID。但我不在乎,因为如果订单号!=订单ID。
稍后,插件将查询付款:
public function search_haystack(){
$pending_variables = $this->pending_orders();
if (empty($pending_variables)){
return;
}
$downloader = new Downloader($options[\'fio_token\']);
$transactionList = $downloader->downloadSince(new \\DateTime(\'-1 week\'));
$allTransactions = $transactionList->getTransactions();
foreach ($allTransactions as $transaction) {
if ($transaction->getAmount()>0){
if($key = array_search($transaction->getVariableSymbol(), array_column($pending_variables, \'number\'))){
$this->maybe_complete_payment($pending_variables[$key][\'id\'],$transaction->getAmount(),$transaction->getCurrency());
}
}
}
}
您猜到了,为了完成付款,我需要订单ID,我将其发送到函数:
public function maybe_complete_payment($variable,$paid_amount,$currency){
$order = new WC_Order($variable);
if (($order->get_total() == $paid_amount) and ($currency == $order->get_currency())){
$order -> payment_complete();
$order -> add_order_note(\'Successfully paired via Bank Transfer\');
}
}
所有的代码都还没有经过测试,但我觉得应该可以正常工作