Wordpress 用于商店订单管理订单的Woocommerce元框选项

Wordpress 用于商店订单管理订单的Woocommerce元框选项,wordpress,woocommerce,Wordpress,Woocommerce,我想在woocommerce的手动管理订单页面中添加一个元框 此元框需要是一个复选框,如果选中该复选框,将触发一个操作 到目前为止,与我所读到的不同,它将需要像这样开始 function add_meta_boxes() { add_meta_box( 'Meta Box', // ID, should be a string. 'woocommerce-action-trigger', // Meta Box Title. 'my_meta_box', // You

我想在woocommerce的手动管理订单页面中添加一个元框

此元框需要是一个复选框,如果选中该复选框,将触发一个操作 到目前为止,与我所读到的不同,它将需要像这样开始

function add_meta_boxes()
 {
add_meta_box( 
    'Meta Box', // ID, should be a string.
    'woocommerce-action-trigger', // Meta Box Title.
    'my_meta_box', // Your call back function, this is where your form field will go.
    'shop_order', // The post type you want this to show up on, can be post, page, or custom post type.
    'side', // The placement of your meta box, can be normal or side.
    'default' // The priority in which this will be displayed.
);
}
然后我需要一个表单,如果管理员选择将触发一个操作

 function triggeraction_meta_box() {
$checkboxMeta = make_action_happen();
}

    <input type="checkbox" name="action" id="action" value="yes" <?php if ( isset ( $checkboxMeta['action'] ) ) checked( $checkboxMeta['action'][0], 'yes' ); ?> />make_action_happen<br />
function triggeraction\u meta\u box(){
$checkboxMeta=使行动发生();
}
函数worg\u add\u custom\u box(){
$screens=['shop_order','wporg_cpt'];
foreach($screens作为$screen){
添加元框(
“worg\u box\u id”,//唯一id
'自定义元框标题',//框标题
“wporg\u custom\u box\u html”//内容回调必须是可调用的类型
$screen//Post-type
);
}
}
添加操作(“添加元框”、“wporg添加自定义框”);
函数worg\u custom\u box\u html($post)
{
$value=get_post_meta($post->ID,'wporg_meta_key',true);
?>
此字段的说明
选择一些。。。
>否则

您应该解释您的代码,除了它只是从WP纪录片复制,并不能解决WooCommerce元框的问题
    function wporg_add_custom_box() {
    $screens = ['shop_order', 'wporg_cpt'];
    foreach ($screens as $screen) {
        add_meta_box(
            'wporg_box_id',           // Unique ID
            'Custom Meta Box Title',  // Box title
            'wporg_custom_box_html',  // Content callback, must be of type callable
            $screen                   // Post type
        );
    }
}
add_action('add_meta_boxes', 'wporg_add_custom_box');



function wporg_custom_box_html($post)
{
    $value = get_post_meta($post->ID, '_wporg_meta_key', true);
    ?>
    <label for="wporg_field">Description for this field</label>
    <select name="wporg_field" id="wporg_field" class="postbox">
        <option value="">Select something...</option>
        <option value="something" <?php selected($value, 'something'); ?>>Something</option>
        <option value="else" <?php selected($value, 'else'); ?>>Else</option>
    </select>
    <?php
}

function wporg_save_postdata($post_id) {
    if (array_key_exists('wporg_field', $_POST)) {
        update_post_meta(
            $post_id,
            '_wporg_meta_key',
            $_POST['wporg_field']
        );
    }
}
add_action('save_post', 'wporg_save_postdata');