因此,我在 WooCoommerce 的 my account/my-orders.php
模板文件上构建一个自定义部分,以仅显示“课程”类别下的任何产品的订单历史记录。
我目前有这个:
<?php
$my_orders_columns = apply_filters(
'woocommerce_my_account_my_orders_columns',
array(
'order-number' => esc_html__( 'Order', 'woocommerce' ),
'order-date' => esc_html__( 'Date', 'woocommerce' ),
'order-status' => esc_html__( 'Status', 'woocommerce' ),
'order-total' => esc_html__( 'Total', 'woocommerce' ),
'order-actions' => ' ',
)
);
$customer_orders = get_posts(
apply_filters(
'woocommerce_my_account_my_orders_query',
array(
'numberposts' => $order_count,
'meta_key' => '_customer_user',
'meta_value' => get_current_user_id(),
'post_type' => wc_get_order_types( 'view-orders' ),
'post_status' => array_keys( wc_get_order_statuses() ),
)
)
);
if ( $customer_orders ) : ?>
<?php if(is_product_category('course')) { ?>
<section class='courseHistory'>
<div class='grid-container full'>
<?php
foreach ( $customer_orders as $customer_order ) :
$order = wc_get_order( $customer_order ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
$item_count = $order->get_item_count();
?>
<div class='grid-x'>
<!-- Course loop to go here -->
<?php foreach ( $my_orders_columns as $column_id => $column_name ) : ?>
<div class='large-12 cell marB20 shadow'>
<div class='grid-x'>
这是按照我想要的方式循环拉取订单历史记录,但我已经在其周围添加了条件if is_product_category('course'),但它没有拉出任何事情都通过。
感觉我很接近但错过了什么?
翻过高山走不出你