【发布时间】:2018-05-16 08:56:10
【问题描述】:
我正在尝试计算客户已取消的订单数量并将其显示在管理订单屏幕中。
我的问题是我不能让它为远程客户工作,我可以让它为我自己工作(作为 current_user)。
这是我的代码(取自其他谷歌搜索和一些小的修改):
function count_order_no( $atts, $content = null ) {
$args = shortcode_atts( array(
'status' => 'cancelled',
), $atts );
$statuses = array_map( 'trim', explode( ',', $args['status'] ) );
$order_count = 0;
foreach ( $statuses as $status ) {
// if we didn't get a wc- prefix, add one
if ( 0 !== strpos( $status, 'wc-' ) ) {
$status = 'wc-' . $status;
}
$order_count += wp_count_posts( 'shop_order' )->$status;
}
ob_start();
echo number_format( $order_count );
return ob_get_clean();
}
add_shortcode( 'wc_order_count', 'count_order_no' );
然后在后台显示号码
// print the number
function print_the_number() {
echo do_shortcode( '[wc_order_count]' );
}
// add the action
add_action( 'woocommerce_admin_order_data_after_order_details', 'print_the_number', 10, 1 );
非常感谢任何帮助!
【问题讨论】:
标签: php wordpress woocommerce backend orders