1
お客様がキャンセルした注文数を数え、管理注文画面に表示しようとしています。Woocommerce管理者の注文編集ページでお客様のキャンセル注文数を表示
私の問題は、遠隔地の顧客のために働くことができないということです。自分自身で(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');
、その後、すべてのヘルプは非常にapreciatedさ
// 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);
adminに番号を表示!
ありがとう、魅力的な作品です!確かにあなたの方法ははるかに簡単で明確です! – RwkY