简体   繁体   English

在 WooCommerce 中编辑我的帐户订单视图页面

[英]Editing My account Order view pages in WooCommerce

In WooCommerce My account "Order view" pages, I'm supposed to add a visual tracking like this:在 WooCommerce 我的帐户“订单视图”页面中,我应该添加这样的视觉跟踪:
在此处输入图片说明

On actual pages, to track every order, above order details:在实际页面上,要跟踪每个订单,上面的订单详细信息:

在此处输入图片说明

  1. 1st problem is i don't know how to add html & php code to the view order page i tried adding hooks on functions.php but it didn't work第一个问题是我不知道如何将 html 和 php 代码添加到视图订单页面我尝试在 functions.php 上添加钩子但它没有用

  2. 2nd problem is that i want to get the status of every order in view order page (Ex: processing or delivered etc.)第二个问题是我想在查看订单页面中获取每个订单的状态(例如:处理或交付等)

Here is my functions.php code to try to achieve it:这是我尝试实现它的functions.php代码:

    // **
//  * Add custom tracking code to the view order page
//  */
add_action( 'woocommerce_view_order', 'my_custom_tracking' );
function my_custom_tracking(){
    $order = wc_get_order( $order_id );

    $order_id  = $order->get_id(); // Get the order ID
    $parent_id = $order->get_parent_id(); // Get the parent order ID (for subscriptions…)

    $user_id   = $order->get_user_id(); // Get the costumer ID
    $user      = $order->get_user(); // Get the WP_User object

    echo $order_status  = $order->get_status(); // Get the order status 
}

There are some errors in your code:您的代码中有一些错误:

  1. The $order_id variable is already included as a function argument for this hook, but is missing in your code . $order_id变量已作为此挂钩的函数参数包含在内,但在您的代码中缺失
  2. You can't use echo with $order_status = $order->get_status();不能将echo$order_status = $order->get_status();

So try instead:所以试试吧:

add_action( 'woocommerce_view_order', 'my_custom_tracking' );
function my_custom_tracking( $order_id ){
    // Get an instance of the `WC_Order` Object
    $order = wc_get_order( $order_id );
    
    // Get the order number
    $order_number  = $order->get_order_number();
    
    // Get the formatted order date created
    $date_created  = wc_format_datetime( $order->get_date_created() );
    
    // Get the order status name
    $status_name  = wc_get_order_status_name( $order->get_status() );
    
    // Display the order status 
    echo '<p>' . __("Order Status:") . ' ' . $status_name . '</p>';
}

Code goes in function.php file of your active child theme (or active theme).代码位于活动子主题(或活动主题)的 function.php 文件中。 Tested and works.测试和工作。


If you want to change the yellow underline texts in your 2nd screenshot, you will have to make changes in myaccount/view-order.php template file:如果要更改第二个屏幕截图中的黄色下划线文本,则必须在myaccount/view-order.php模板文件中进行更改:

  1. First read official documentation to understand "how to Override templates via a theme" .首先阅读官方文档以了解 “如何通过主题覆盖模板”

  2. Once done and once copied WooCommerce templates to your active theme as explained on the documentation, open edit myaccount/view-order.php template file.完成并按照文档中的说明将 WooCommerce 模板复制到您的活动主题后,打开编辑myaccount/view-order.php模板文件。

  3. The changes to make are located in lines from 26 to 34:要进行的更改位于第 26 到 34 行:

     <p><?php /* translators: 1: order number 2: order date 3: order status */ printf( __( 'Order #%1$s was placed on %2$s and is currently %3$s.', 'woocommerce' ), '<mark class="order-number">' . $order->get_order_number() . '</mark>', '<mark class="order-date">' . wc_format_datetime( $order->get_date_created() ) . '</mark>', '<mark class="order-status">' . wc_get_order_status_name( $order->get_status() ) . '</mark>' ); ?></p>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 Woocommerce 的我的帐户订单视图页面上添加 sku 以订购商品 - Add the sku to order items on my account order view pages in Woocommerce 在 Woocommerce 3 中的我的帐户订单查看页面上显示付款说明 - Display payment instructions on my account order view pages in Woocommerce 3 WooCommerce -Thankyou 和“我的帐户”查看订单页面上的自定义通知 - WooCommerce - Custom notice on Thankyou and "My account" view order pages 在WooCommerce我的帐户查看订单页面上的订单详细信息下添加自定义文本 - Add custom text under order details on WooCommerce My account view order pages Woocommerce 我账户中的订单查看页面显示 404 not found - Woocommerce order-view page in my account show 404 not found 在 WooCommerce 我的帐户中更改标题自定义“查看订单”端点 - Change title custom "view-order" endpoint in WooCommerce My account Woocommerce 查看订单链接无我的帐户 - Woocommerce view-order link without my-account 在我的帐户查看订单页面中用 Sku 替换产品名称 - Replace the product name by the Sku in My account view order pages 检测 WooCommerce“我的帐户”页面的仪表板 - Detect dashboard of WooCommerce "my account" pages 更改 Woocommerce 中我的帐户页面上的标题 - Changing the titles on My Account pages in Woocommerce
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM