private function getEarliestDateOrNull($snapshotDate = null, $preexistingEpisodeDate = null)
{
$date = null;
if ($snapshotDate instanceof DateTime && $preexistingEpisodeDate instanceof DateTime) {
$date = $snapshotDate < $preexistingEpisodeDate ? $snapshotDate : $preexistingEpisodeDate;
} elseif ($snapshotDate instanceof DateTime) {
$date = $snapshotDate;
} elseif ($preexistingEpisodeDate instanceof DateTime) {
$date = $preexistingEpisodeDate;
}
return ($date instanceof DateTime) ? $date->format('m/d/Y') : null;
}
问题出在我的getEarliestDateorNull中,elseif语句是唯一由于某种原因无法读取的测试。有没有办法从elseif语句中更改它们?我的意思是说,如果可以有一个SWITCH实现。测试在php 7中运行。
答案 0 :(得分:0)
经过多次试验和错误,如果您将其设置为elseif
而不是function mysite_hold($order_id) {
$order = new WC_Order($order_id);
$items = $order->get_items();
$backorder = FALSE;
foreach ($items as $item) {
if ($item['Backordered']) {
$backorder = TRUE;
break;
}
}
if($backorder){
$order->update_status('completed'); //change your status here
}
}
add_action('woocommerce_order_status_on-hold', 'mysite_hold');
//You may need to store your backorder info like below
wc_add_order_item_meta($item_id, 'Backordered', $qty - max(0, $product->get_total_stock()));
它应该有效:)