如何编辑订单表的布局(orders.php)

发布于 2025-01-20 08:24:45 字数 1209 浏览 2 评论 0原文

我想更改orders.php中存在的表的布局。具体而言,我希望每种产品都有包含数据(名称,日期,状态等)的行(名称,日期,状态等),而是为每种产品提供单独的水平卡。

示例 https://i.sstatic.net/itdgu.png 。我正在尝试使用短代码来执行此操作,但是我不确定这是否正确。谁能给我指示?

目前,我正在尝试这种方式:下面的代码可以正常工作并正确返回所有订单号。但是,我将所有订单编号并排作为简单的文本行, https:// i。 sstatic.net/rqdvc.png 。我不知道如何插入div或CSS类以更改布局。

即使我添加CSS类,剩下的问题是如何添加其他元素,例如名称,价格,状态等。不确定是否可以在一个短代码中完成。建议 ?

// GET ALL ORDERS NUMBER OF CURRENT USER

// Give the callback function a clear and descriptive name.
add_shortcode( 'prcsed_order_numbers' , 'prcsed_order_1' );
function prcsed_order_1() {
 
// Get all orders for the current user.
   $customer_orders = wc_get_orders([
    'customer_id' => get_current_user_id(),
   ]);

// Transform the array of order objects into an array of order names.
   $order_numbers = array_map( function( $order ) {
       return $order->get_order_number();
   }, $customer_orders );

// Return as a string, ready for output,
   return implode( ', ', $order_numbers );
}

I want to change the layout of table present in orders.php. Specifically, instead of having rows containing the data (name, date, status, etc.), I want separate horizontal cards for each product.

Example: https://i.sstatic.net/itdGU.png. I'm trying to do this with a shortcode, but I'm not sure if that's the right way. Can anyone give me directions ?

For now I'm trying this way: The code below works and returns all order numbers correctly. However I am getting all the order numbers side by side as a simple line of text: https://i.sstatic.net/RqdVC.png. I don't know how to insert div, or css classes to change the layout.

Even if I add css classes, the question that remains is how to add other elements such as name, price, status etc. Not sure it can all be done in one shortcode. Advice ?

// GET ALL ORDERS NUMBER OF CURRENT USER

// Give the callback function a clear and descriptive name.
add_shortcode( 'prcsed_order_numbers' , 'prcsed_order_1' );
function prcsed_order_1() {
 
// Get all orders for the current user.
   $customer_orders = wc_get_orders([
    'customer_id' => get_current_user_id(),
   ]);

// Transform the array of order objects into an array of order names.
   $order_numbers = array_map( function( $order ) {
       return $order->get_order_number();
   }, $customer_orders );

// Return as a string, ready for output,
   return implode( ', ', $order_numbers );
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

紧拥背影 2025-01-27 08:24:45

扩展我之前输入的内容。您可以使用您在 $order_numbers 中所做的操作来访问更多订单变量。这是我在独立的 WooCommerce 测试网站上测试过的内容。您将需要输入客户 ID 函数并修改返回的 HTML 结构,以简化样式和编辑。我所拥有的并不干净,但确实有效。

$results = wc_get_orders([ 'cutomer_id'=>1 ]);

foreach ( $results as $order ) {    
    $first_name = $order->get_billing_first_name();
    $last_name = $order->get_billing_last_name();
    $status = $order->get_status();
    
    echo '<h1>' . $first_name . ' ' . $last_name . '</h1><p>' . $status . '</p>';
}

以下链接为您提供了您需要访问的订单对象的函数/挂钩。 https://www .businessbloomer.com/woocommerce-easily-get-order-info-total-items-etc-from-order-object/

Expanding on what I was typing before. You can access more order variables using what you were already doing in $order_numbers. Here is what I have tested on standalone WooCommerce test site. You will need to input your customer ID function and modify the return HTML structure for styling and editing simplicity. What I have is not clean but does work.

$results = wc_get_orders([ 'cutomer_id'=>1 ]);

foreach ( $results as $order ) {    
    $first_name = $order->get_billing_first_name();
    $last_name = $order->get_billing_last_name();
    $status = $order->get_status();
    
    echo '<h1>' . $first_name . ' ' . $last_name . '</h1><p>' . $status . '</p>';
}

The following link gives you the functions/hooks for the order object that you will need accessing to. https://www.businessbloomer.com/woocommerce-easily-get-order-info-total-items-etc-from-order-object/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文