[英]Woocommerce custom order status change date
在Woocommerce中,我想在将订单状态更新为自定义订单状态时显示日期和时间。 我正在使用$order->get_date_modified();
但这不适合:
$order_transporte = wc_get_order_status_name( $order->get_status() );
if($order_transporte == "Transporte"){
$date_modified = $order->get_date_modified();
echo sprintf( '<tr><td>%s</td><td>Transporte</td></tr>', $date_modified->date("d/M/Y g:i:s"));
}
woocommerce中是否有任何功能可以从特定状态获取更新日期?
对于自定义订单状态,您可以使用woocommerce_order_status_{$status_transition[to]}
复合操作钩,在其中您将用自定义状态段替换{$status_transition[to]}
以设置此自定义状态的更改日期,例如:
add_action( 'woocommerce_order_status_transporte', 'action_on_order_status_transporte', 10, 2 );
function action_on_order_status_transporte( $order_id, $order ) {
// Set your default time zone (http://php.net/manual/en/timezones.php)
date_default_timezone_set('Europe/Paris');
$order->update_meta_data('_date_transporte', strtotime("now") );
$order->save();
}
代码进入您的活动子主题(或活动主题)的function.php文件中。 经过测试和工作。
然后,将使用以下内容显示自定义状态日期/时间更改:
if( $order->has_status('transporte') ){
// Set your default time zone (http://php.net/manual/en/timezones.php)
date_default_timezone_set('Europe/Paris');
$date_transporte = date( "d/M/Y g:i:s", $order->get_meta('_date_transporte') );
echo '<tr><td>'.$date_transporte.'</td><td>'.__("Transporte").'</td></tr>';
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.