php - 在 Woocommerce 我的帐户查看订单页面中为自定义状态启用“重新排序”按钮
问题描述
我需要在我的 Woocommerce 网站上请求报价系统,但找不到任何与复合产品插件兼容的系统。因此,我将让客户使用“不发货/报价”发货选项和“请求报价支付网关”正常结账。这样我可以在后端看到报价,批准它们,然后客户可以订购(从技术上重新排序)他们在我的帐户部分的报价。
我得到了 Completed orders 和 Quote Approved 的按钮来显示使用这个:
/**
* Add order again button in my orders completed actions.
*
* @param array $actions
* @param WC_Order $order
* @return array
*/
function cs_add_order_again_to_my_orders_actions( $actions, $order ) {
if ( $order->has_status( 'completed' ) ) {
$actions['order-again'] = array(
'url' => wp_nonce_url( add_query_arg( 'order_again', $order->id ) , 'woocommerce-order_again' ),
'name' => __( 'Order Again', 'woocommerce' )
);
}
return $actions;
}
add_filter( 'woocommerce_my_account_my_orders_actions', 'cs_add_order_again_to_my_orders_actions', 50, 2 );
/**
* Add Place order button in my orders quote-approved actions.
*
* @param array $actions
* @param WC_Order $order
* @return array
*/
function cs_add_place_order_to_my_orders_actions( $actions, $order ) {
if ( $order->has_status( 'quote-approved' ) ) {
$actions['place-order'] = array(
'url' => wp_nonce_url( add_query_arg( 'order_again', $order->id ) , 'woocommerce-place_order' ),
'name' => __( 'place order', 'woocommerce' )
);
}
return $actions;
}
add_filter( 'woocommerce_my_account_my_orders_actions', 'cs_add_place_order_to_my_orders_actions', 50, 2 );
但是我的第二个按钮不起作用,我相信是因为这个:
if ( ! function_exists( 'woocommerce_order_again_button' ) ) {
/**
* Display an 'order again' button on the view order page.
*
* @param object $order Order.
*/
function woocommerce_order_again_button( $order ) {
if ( ! $order || ! $order->has_status( apply_filters( 'woocommerce_valid_order_statuses_for_order_again', array( 'completed' ) ) ) || ! is_user_logged_in() ) {
return;
}
wc_get_template( 'order/order-again.php', array(
'order' => $order,
) );
}
}
在 woocommerce/includes/wc-template-functions.php
所以我想我只需要添加 'quote-approved' 到
woocommerce_valid_order_statuses_for_order_again
大批
我尝试使用这个:
//Make order again work for Place order , see below
add_filter('woocommerce_valid_order_statuses_for_order_again', function( $statuses ){
$statuses = wc_get_order_statuses('completed', 'quote-approved');
return $statuses;
}, 10, 2);
我在这里找到的:Woocommerce - Allowing Order Again for different statuss
但我无法让它工作。有人知道我在做什么错吗?任何帮助将不胜感激。谢谢!
解决方案
问题来自wc_get_order_statuses()
没有参数的函数,只是给出了所有可用订单状态的索引数组。
相反,您只需要以这种方式添加您的自定义订单状态信息:
add_filter( 'woocommerce_valid_order_statuses_for_order_again', 'add_custom_status_for_order_again', 20, 1 );
function add_custom_status_for_order_again( $statuses ){
$statuses[] = 'quote-approved';
return $statuses;
}
代码位于您的活动子主题(或活动主题)的 function.php 文件中。测试和工作。
推荐阅读
- typescript - 实例化通用对象时出现类型错误
- php - 我怎样才能防止 EDD 销售捆绑产品而只销售实物产品
- javascript - 如何使用 vanilla javascript 从用户的媒体文件中获取频率?
- android - 如何在android studio中更改属性列的宽度
- python-3.x - 我们可以使用 TensorflowLite 在 Raspberry Pi3 上运行多个深度学习模型进行推理吗
- laravel - 使用带有 Laravel Vue 应用程序的 vue-router,如果我在登录后转到基本 URL,它会显示 404
- android - Delphi Rio10.3.2中如何添加和删除Android通知通道
- python - 是否有与 R 中的 powertransform 等效的 Python 函数
- javascript - 页面未加载反应js
- c# - 为什么我可以引用 select new 中不在 select from 语句中的表