如何在my-orders.php页面中为最近的订单循环产品名称和照片?

乌彭德拉·沙玛(Upendra Sharma)

我必须在最近的订单页面上添加产品名称和缩略图。如果一个订单中有多个产品,我不知道如何循环播放。

(死图像链接已删除)

LoicTheAztec

我刚刚为产品名称设置了循环,但我尚未对其进行测试。您将必须搜索缩略图(请参阅最后的链接)。

对于产品循环,我使用了Sandeep Kumar的代码:WooCommerce在我的帐户中显示订单产品名称

foreach($order->get_items() as $item) {
    $product_name = $item['name'];
}

您的自定义模板的代码如下:

.my_product_name {
    display: block;
}
<?php
/**
 * My Orders
 *
 * Shows recent orders on the account page
 *
 * @author  WooThemes
 * @package WooCommerce/Templates
 * @version 2.3.10
 */
 
if ( ! defined( 'ABSPATH' ) ) {
    exit; // Exit if accessed directly
}
 
$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() )
) ) );
 
$user_id = get_current_user_id();
 
if ( $customer_orders ) : ?>
 
    <h2><?php echo apply_filters( 'woocommerce_my_account_my_orders_title', __( 'Recent Orders', 'woocommerce' ) ); ?></h2>
 
    <table class="shop_table shop_table_responsive my_account_orders">
 
        <thead>
            <tr>
                <th class="order-number"><span class="nobr"><?php _e( 'Order', 'woocommerce' ); ?></span></th>
                <th class="order-date"><span class="nobr"><?php _e( 'Date', 'woocommerce' ); ?></span></th>
                <th class="shipping-name"><span class="nobr"><?php _e( 'Customer name', 'woocommerce' ); ?></span></th>
                <th class="products-names"><span class="nobr"><?php _e( 'Products names', 'woocommerce' ); ?></span></th>
                <th class="order-status"><span class="nobr"><?php _e( 'Status', 'woocommerce' ); ?></span></th>
                <th class="order-total"><span class="nobr"><?php _e( 'Total', 'woocommerce' ); ?></span></th>
                <th class="order-actions">&nbsp;</th>
            </tr>
        </thead>
 
        <tbody><?php
            foreach ( $customer_orders as $customer_order ) {
                $order = wc_get_order( $customer_order );
                $order->populate( $customer_order );
                $item_count = $order->get_item_count();
 
                ?><tr class="order">
                    <td class="order-number" data-title="<?php esc_attr_e( 'Order Number', 'woocommerce' ); ?>">
                        <a href="<?php echo esc_url( $order->get_view_order_url() ); ?>">
                            <?php echo _x( '#', 'hash before order number', 'woocommerce' ) . $order->get_order_number(); ?>
                        </a>
                    </td>
                    <td class="order-date" data-title="<?php esc_attr_e( 'Date', 'woocommerce' ); ?>">
                        <time datetime="<?php echo date( 'Y-m-d', strtotime( $order->order_date ) ); ?>" title="<?php echo esc_attr( strtotime( $order->order_date ) ); ?>"><?php echo date_i18n( get_option( 'date_format' ), strtotime( $order->order_date ) ); ?></time>
                    </td>
                    <td class="shipping-name" data-title="<?php esc_attr_e( 'Customer name', 'woocommerce' ); ?>">
                        <span><?php echo get_the_author_meta( 'billing_first_name', $user_id ).' '.get_the_author_meta( 'billing_last_name', $user_id ); ?></span>
                    </td>
                    <td class="products-names" data-title="<?php esc_attr_e( 'Products names', 'woocommerce' ); ?>">
                    <?php 
                        foreach($order->get_items() as $item) {
                            $product_name = $item['name'];
                    ?>
                        <span class="my_product_name"><?php echo $product_name; ?></span>
                     <?php } ?>
                    </td>
                    <td class="order-status" data-title="<?php _e( 'Status', 'woocommerce' ); ?>" style="text-align:left; white-space:nowrap;">
                        <?php
                        if($order->get_status()=='completed')
                        {
                            echo 'Dispatched';
                        }
                        else{
                         echo wc_get_order_status_name( $order->get_status() );
                         }
                          ?>
                    </td>
                    <td class="order-total" data-title="<?php esc_attr_e( 'Total', 'woocommerce' ); ?>">
                        <?php echo sprintf( _n( '%s for %s item', '%s for %s items', $item_count, 'woocommerce' ), $order->get_formatted_order_total(), $item_count ); ?>
                    </td>
                    <td class="order-actions">
                        <?php
                            $actions = array();
 
                            if ( in_array( $order->get_status(), apply_filters( 'woocommerce_valid_order_statuses_for_payment', array( 'pending', 'failed' ), $order ) ) ) {
                                $actions['pay'] = array(
                                    'url'  => $order->get_checkout_payment_url(),
                                    'name' => __( 'Pay', 'woocommerce' )
                                );
                            }
 
                            if ( in_array( $order->get_status(), apply_filters( 'woocommerce_valid_order_statuses_for_cancel', array( 'pending', 'failed' ), $order ) ) ) {
                                $actions['cancel'] = array(
                                    'url'  => $order->get_cancel_order_url( wc_get_page_permalink( 'myaccount' ) ),
                                    'name' => __( 'Cancel', 'woocommerce' )
                                );
                            }
 
                            $actions['view'] = array(
                                'url'  => $order->get_view_order_url(),
                                'name' => __( 'View', 'woocommerce' )
                            );
 
                            $actions = apply_filters( 'woocommerce_my_account_my_orders_actions', $actions, $order );
 
                            if ( $actions ) {
                                foreach ( $actions as $key => $action ) {
                                    echo '<a href="' . esc_url( $action['url'] ) . '" class="button ' . sanitize_html_class( $key ) . '">' . esc_html( $action['name'] ) . '</a>';
                                }
                            }
                        ?>
                    </td>
                </tr><?php
            }
        ?></tbody>
 
    </table>
 
<?php endif; ?>

对于您的产品缩略图,请通过helgatheviking解决方案查看此主题:Echo woocommerce产品缩略图?

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何在WooCommerce“我的帐户”订单表的新列中显示产品名称

如何在API中显示产品名称?

如何从laravel中包含product_id的订单表中获取产品名称?

如何在图表JS中为每个条形显示不同的产品名称

如何选择和显示数组中的产品,并按相同的产品名称排序

如何在 Shopify 网站上居中显示产品名称和定价信息?

如何在sql中根据颜色显示不同的产品名称?

如何在Visual Studio发布后事件中获取产品名称?

如何从AssemblyInfo获取产品名称和产品描述?

如何创建PHP搜索产品名称或产品设计师?

WooCommerce:如何在管理产品列表中的产品名称旁边添加产品类型

如何在Windows上从USB设备的VID和PID获取供应商名称和产品名称?

如何从产品名称中提取品牌

如何使Opencart 1.5.6 url使用产品名称

如何使用jQuery动态获取产品名称和图像?

如何使用NLTK获取时间和日期或特定的产品名称?

如何使用Selenium和Python提取产品名称

如何遍历超市网站并获得产品名称和价格?

如何从重复的行中清空产品名称

如何使用laravel从数据透视表中获取产品名称?

如何以编程方式在woocommerce中到处更改产品名称?

如何使用产品名称获取数组变量中的所有属性值?

Laravel,如果产品ID存储在购物车中,如何从产品表中获取产品名称

如何将订单的前3张图片插入woocommerce my-orders表中?

如何将小于 10 的产品名称、颜色及其颜色数量输出为列表?

Woocommerce - 如何获取当前用户的所有订单(用于 Orders.php 页面)

如何使用LINQ查询获取名称以数字开头的产品名称列表?

MSI如何在同一计算机上的其他用户的“添加/删除程序”列表中添加产品名称

如何搜索Spree :: Orders和带有ransack gem的关联