[英]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:在实际页面上,要跟踪每个订单,上面的订单详细信息:
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 上添加钩子但它没有用
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:您的代码中有一些错误:
$order_id
variable is already included as a function argument for this hook, but is missing in your code . $order_id
变量已作为此挂钩的函数参数包含在内,但在您的代码中缺失。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
模板文件中进行更改:
First read official documentation to understand "how to Override templates via a theme" .首先阅读官方文档以了解 “如何通过主题覆盖模板” 。
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
模板文件。
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.