每当我触发自定义操作时,都会显示成功消息“订单已更新”。
有没有办法在触发自定义订单操作后隐藏此消息?例如,如果我的操作没有处理?
function _custom_order_action_process( $order ) {
// some code
// some code
// some code
if ( ! $valid1 ) {
// Oooops...
return;
}
if ( ! $valid2 ) {
return;
}
//here we go...
}
add_action( 'woocommerce_order_action_custom_order_action','_custom_order_action_process' );
答案 0 :(得分:1)
您可以做的一件事就是更改消息值
我们可以使用redirect_post_location
。
function _custom_order_action_process( $order ) {
// some code
// some code
// some code
if ( ! $valid1 ) {
// Oooops...
add_filter( 'redirect_post_location', 'redirect_post_location', 99 );
}
if ( ! $valid2 ) {
add_filter( 'redirect_post_location', 'redirect_post_location', 99 );
}
//here we go...
}
add_action( 'woocommerce_order_action_custom_order_action','_custom_order_action_process' );
function redirect_post_location( $location ) {
remove_filter( 'redirect_post_location', __FUNCTION__, 99 ); // remove this filter so it will only work with your validations.
$location = add_query_arg('message', 99, $location); // 99 is empty message, it will not show. Or if by any chance it has a message, you change to higher number.
return $location;
}