당신은 당신의 접근 방식을 처음 시도 할 수 "new WC_Order($order_id);
",이 방법 :
function destinationStep($order_id)
global $woocommerce;
$order = new WC_Order($order_id);
$items = $order->get_items();
// echo var_dump($items);
//----
foreach ($items as $key => $item) {
$product_name = $item['name'];
$product_id = $item['product_id'];
$terms = get_the_terms($product_id, 'product_cat');
// echo var_dump($terms);
foreach ($terms as $term) {
// Categories by slug
$product_cat_slug= $term->slug;
}
}
add_action('woocommerce_multistep_checkout_before_order_info', 'destinationStep', 10, 1);
여전히 "new WC_Order($post->ID)
" 접근 방식을 시도 작동하지 않는 경우 :
function destinationStep()
global $woocommerce, $post;
$order = new WC_Order($post->ID);
$items = $order->get_items();
// echo var_dump($items);
//----
foreach ($items as $key => $item) {
$product_name = $item['name'];
$product_id = $item['product_id'];
$terms = get_the_terms($product_id, 'product_cat');
// echo var_dump($terms);
foreach ($terms as $term) {
// Categories by slug
$product_cat_slug= $term->slug;
}
}
add_action('woocommerce_multistep_checkout_before_order_info', 'destinationStep');
업데이트 - 몇 가지 생각 후 :
당신 아직 존재하지 않기 때문에, ''post_type '=>'shop_order '에 대한 주문 ID를 얻을 수 없습니다. 이 주문 ID는 고객이 주문을 제출할 때 생성되지만 결제 전 페이지에는 생성되지 않습니다.
그래서이 경우 빈 배열을 얻는 것이 정상입니다.
안녕하십니까, 죄송합니다. 답장을 보내 주시겠습니까? 나는 처음에는 코드의 첫 번째 비트만을 사용하고 var 덤프를 얻으려고한다. 두 var 덤프 모두 빈 배열입니다. 어떤 충고? 우리가 이걸 갈 수 있다면 나는 데킬라를 사줄거야. –
그래, 그걸 시도해 봤어. 루프가없는 첫 번째 부분. 그냥 빈 배열. –
그냥 다른 사람이 읽은 것입니다 도움을 upvoted, 그것은 나를 위해 일하는 것이 아닙니다. –