我使用了这段代码:
http://rubular.com/r/YG1pnCzdUC
在 sv_wc_process_order_meta_box_action
功能中,如何向管理员显示消息框?
目前代码使用 update_post_meta()
功能和 add_order_note()
方法,不向管理员显示任何消息。
感谢。
答案 0 :(得分:1)
我知道的唯一方法是使用带有 admin_notices
操作挂钩的自定义函数。因此,您可以尝试在所使用的代码中包含相关的 add_action()
。
此代码未经测试,我不保证任何内容:
// The message function to be hooked in 'admin_notices' hook.
function my_custom_admin_notice() {
?>
<div class="notice notice-success is-dismissible">
<p><?php _e('Order has been updated "printed for packaging"'); ?></p>
</div>
<?php
}
//The second function that you use (customized with an add_action()):
function sv_wc_process_order_meta_box_action( $order ) {
// add the order note
$message = sprintf( __( 'Order information printed by %s for packaging.', 'my-textdomain' ), wp_get_current_user()->display_name );
$order->add_order_note( $message );
// add the flag so this action won't be shown again
update_post_meta( $order->id, '_wc_order_marked_printed_for_packaging', 'yes' );
// Setting the admin message function in 'admin_notices' hook.
add_action('admin_notices', 'my_custom_admin_notice');
}
add_action( 'woocommerce_order_action_wc_custom_order_action', 'sv_wc_process_order_meta_box_action' );
相关文档: