我试图添加跟踪订单按钮到我的帐户>订单页面,让游客检查航运跟踪从那里。该按钮具有跟踪服务的链接,该跟踪服务的跟踪编号是从公共秩序便笺中收集的(在我的示例中是这样存储跟踪编号的)。我设法创建了“跟踪”按钮,但“查看”按钮消失了,以便执行以下命令。当应用代码时,它看起来是这样的-- https://gyazo.com/498975ca43b09bce231a527ee782729a、第二和第三阶应该有“视图”按钮。
AFAIK --这是因为这些订单缺少从哪里收集跟踪号码的公共秩序说明,但我不明白它如何影响“查看”按钮。
这是我的代码:
function my_code_add_myaccount_order_track_button( $actions, $order ) {
$order_notes = $order->get_customer_order_notes();
foreach ( $order_notes as $order_note ) {
$actions['track'] = array(
'url' => 'https://t.17track.net/en#nums=' . substr($order_note->comment_content, strpos($order_note->comment_content, "number:") + 8, 13),
'name' => __( 'Track', 'my-textdomain' ),
);
return $actions;
}
}
add_filter( 'woocommerce_my_account_my_orders_actions', 'my_code_add_myaccount_order_track_button', 10, 2 );发布于 2019-12-15 14:38:21
我找到了一种解决这个问题的方法,在没有针对特定秩序的公共秩序评论的情况下,添加一个函数来保释。下面是代码:
function my_code_add_myaccount_order_track_button( $actions, $order ) {
$order_notes = $order->get_customer_order_notes();
if ( empty ($order_notes) ) {
return $actions;
}
else {
foreach ( $order_notes as $order_note ) {
$actions['track'] = array(
'url' => 'https://t.17track.net/en#nums=' . substr($order_note->comment_content, strpos($order_note->comment_content, "number:") + 8, 13),
'name' => __( 'Track', 'my-textdomain' ),
);
return $actions;
}
}
}
add_filter( 'woocommerce_my_account_my_orders_actions', 'my_code_add_myaccount_order_track_button', 10, 2 );https://stackoverflow.com/questions/59337510
复制相似问题