【问题标题】:Hide orders with status (Pending Payment) on WooCommerce My Account page在 WooCommerce 我的帐户页面上隐藏状态为(待付款)的订单
【发布时间】:2021-01-17 04:50:59
【问题描述】:

'Hiding order status in My Account recent orders list page' 的启发,我尝试在“我的帐户”页面上隐藏状态为(待付款)的订单。

我稍微修改了代码,但我无法让它工作。

add_filter('woocommerce_my_account_my_orders_actions', 'custom_removing_order_status_pending_payment', 10, 1);

function custom_removing_order_status_pending_payment( $order ){
    unset($order['wc-pending']);
    return $order;
}

我非常感谢任何帮助。谢谢。

【问题讨论】:

  • 这是“操作”列中按钮的过滤器(顺便说一下,它接受两个参数,$actions 和 $order)。您只想隐藏“查看”按钮还是隐藏整个订单?
  • @Terminator-Barbapapa 仅隐藏状态为(待付款)的订单
  • 是的,但隐藏整个订单行,还是只隐藏“查看”按钮?
  • @Terminator-Barbapapa 整行订单处于状态(待付款)。

标签: php wordpress woocommerce


【解决方案1】:

现在您正在使用woocommerce_my_account_my_orders_actions 过滤器,它可以让您过滤“我的帐户”页面上“操作”列中的按钮。

如果您想从订单列表中过滤掉某些订单状态,您必须使用woocommerce_my_account_my_orders_query 过滤器。

add_filter( 'woocommerce_my_account_my_orders_query', 'unset_pending_payment_orders_from_my_account', 10, 1 );
function unset_pending_payment_orders_from_my_account( $args ) {
    $statuses = wc_get_order_statuses();    
    unset( $statuses['wc-pending'] );
    $args['post_status'] = array_keys( $statuses );
    return $args;
}

【讨论】:

  • 非常感谢您的帮助,效果很好,来自委内瑞拉的问候。
  • 您知道如何在订单管理页面中隐藏状态(待付款)吗?
  • 谢谢,我已经解决了。它不起作用,因为我使用的是 woocommerce 订单状态管理器插件。
猜你喜欢
  • 2020-08-20
  • 2020-11-03
  • 2022-10-05
  • 1970-01-01
  • 1970-01-01
  • 2017-06-27
  • 1970-01-01
  • 2019-02-21
  • 2021-02-17
相关资源
最近更新 更多