Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/255.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何将自定义字段添加到“编辑订单”页面_Php_Woocommerce_Field_Admin_Orders - Fatal编程技术网

Php 如何将自定义字段添加到“编辑订单”页面

Php 如何将自定义字段添加到“编辑订单”页面,php,woocommerce,field,admin,orders,Php,Woocommerce,Field,Admin,Orders,我一直在谷歌上搜索,寻找一种简单的方法,在编辑订单页面中添加一个空字段框。我们将使用此信息为我们的快递提供装运参考 我们会将它添加到订单注释中,但我们希望它是可搜索的,并且还希望将它添加为订单管理页面中的一列(我有一个管理列插件,我认为它可以做到这一点,我只需要添加此字段开始) 希望有人能帮忙,谢谢 编辑: 我发现这个问题似乎很相似,但比我要找的更复杂,我不知道如何简化它 我不需要像这样在前端向客户展示任何东西。只是一个简单的空框,显示在每个可以搜索的订单编辑页面上(可能在订单注释下方)。然后我

我一直在谷歌上搜索,寻找一种简单的方法,在编辑订单页面中添加一个空字段框。我们将使用此信息为我们的快递提供装运参考

我们会将它添加到订单注释中,但我们希望它是可搜索的,并且还希望将它添加为订单管理页面中的一列(我有一个管理列插件,我认为它可以做到这一点,我只需要添加此字段开始)

希望有人能帮忙,谢谢

编辑:

我发现这个问题似乎很相似,但比我要找的更复杂,我不知道如何简化它

我不需要像这样在前端向客户展示任何东西。只是一个简单的空框,显示在每个可以搜索的订单编辑页面上(可能在订单注释下方)。然后我也会在订单管理页面的一列中显示它。

使用订单编辑页面底部部分的默认自定义字段

使用订单编辑页面底部部分的默认自定义字段


设法得到了答案,这非常有效

//from::https://codex.wordpress.org/Plugin_API/Action_Reference/manage_posts_custom_column

// For displaying in columns.

add_filter( 'manage_edit-shop_order_columns', 'set_custom_edit_shop_order_columns' );
function set_custom_edit_shop_order_columns($columns) {
    $columns['custom_column'] = __( 'Custom Column', 'your_text_domain' );
    return $columns;
}

// Add the data to the custom columns for the order post type:
add_action( 'manage_shop_order_posts_custom_column' , 'custom_shop_order_column', 10, 2 );
function custom_shop_order_column( $column, $post_id ) {
    switch ( $column ) {

        case 'custom_column' :
            echo esc_html( get_post_meta( $post_id, 'custom_column', true ) );
            break;

    }
}

// For display and saving in order details page.
add_action( 'add_meta_boxes', 'add_shop_order_meta_box' );
function add_shop_order_meta_box() {

    add_meta_box(
        'custom_column',
        __( 'Custom Column', 'your_text_domain' ),
        'shop_order_display_callback',
        'shop_order'
    );

}

// For displaying.
function shop_order_display_callback( $post ) {

    $value = get_post_meta( $post->ID, 'custom_column', true );

    echo '<textarea style="width:100%" id="custom_column" name="custom_column">' . esc_attr( $value ) . '</textarea>';
}

// For saving.
function save_shop_order_meta_box_data( $post_id ) {

    // If this is an autosave, our form has not been submitted, so we don't want to do anything.
    if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
        return;
    }

    // Check the user's permissions.
    if ( isset( $_POST['post_type'] ) && 'shop_order' == $_POST['post_type'] ) {
        if ( ! current_user_can( 'edit_shop_order', $post_id ) ) {
            return;
        }
    }

    // Make sure that it is set.
    if ( ! isset( $_POST['custom_column'] ) ) {
        return;
    }

    // Sanitize user input.
    $my_data = sanitize_text_field( $_POST['custom_column'] );

    // Update the meta field in the database.
    update_post_meta( $post_id, 'custom_column', $my_data );
}

add_action( 'save_post', 'save_shop_order_meta_box_data' );

//发件人::https://codex.wordpress.org/Plugin_API/Action_Reference/manage_posts_custom_column
//用于在列中显示。
添加过滤器('manage_edit-shop_order_columns','set_custom_edit_shop_order_columns');
函数集\自定义\编辑\车间\订单\列($columns){
$columns['custom_column']=uuu('custom column','your_text_domain');
返回$columns;
}
//将数据添加到订单投递类型的自定义列:
添加操作('manage_shop_order_posts_custom_column','custom_shop_order_column',10,2);
函数自定义\车间\订单\列($column,$post\u id){
开关($列){
案例“自定义_列”:
echo esc_html(get_post_meta($post_id,'custom_column',true));
打破
}
}
//用于在订单详细信息页面中显示和保存。
添加操作('add_meta_box'、'add_shop_order_meta_box');
函数add\u shop\u order\u meta\u box(){
添加元框(
“自定义_列”,
__(“自定义列”、“您的\u文本\u域”),
“店铺、订单、显示、回拨”,
“商店订单”
);
}
//用于显示。
功能车间\订单\显示\回拨($post){
$value=get\u post\u meta($post->ID,'custom\u column',true);
回显“”。esc_attr($value)。“”;
}
//为了节省。
函数save_shop_order_meta_box_data($post_id){
//如果这是自动保存,则我们的表单尚未提交,因此我们不想执行任何操作。
if(已定义('DOING_AUTOSAVE')&&DOING_AUTOSAVE){
返回;
}
//检查用户的权限。
如果(isset($\u POST['POST\u type'])和&“shop\u order'==$\u POST['POST\u type'])){
如果(!当前用户可以('edit_shop_order',$post_id)){
返回;
}
}
//确保它已设置。
如果(!isset($\u POST['custom\u column'])){
返回;
}
//清理用户输入。
$my_data=sanitize_text_字段($_POST['custom_column']);
//更新数据库中的元字段。
更新发布元数据($post\u id,$custom\u column',$my\u data);
}
添加操作('save_post'、'save_shop_order_meta_box_data');

设法得到了答案,这非常有效

//from::https://codex.wordpress.org/Plugin_API/Action_Reference/manage_posts_custom_column

// For displaying in columns.

add_filter( 'manage_edit-shop_order_columns', 'set_custom_edit_shop_order_columns' );
function set_custom_edit_shop_order_columns($columns) {
    $columns['custom_column'] = __( 'Custom Column', 'your_text_domain' );
    return $columns;
}

// Add the data to the custom columns for the order post type:
add_action( 'manage_shop_order_posts_custom_column' , 'custom_shop_order_column', 10, 2 );
function custom_shop_order_column( $column, $post_id ) {
    switch ( $column ) {

        case 'custom_column' :
            echo esc_html( get_post_meta( $post_id, 'custom_column', true ) );
            break;

    }
}

// For display and saving in order details page.
add_action( 'add_meta_boxes', 'add_shop_order_meta_box' );
function add_shop_order_meta_box() {

    add_meta_box(
        'custom_column',
        __( 'Custom Column', 'your_text_domain' ),
        'shop_order_display_callback',
        'shop_order'
    );

}

// For displaying.
function shop_order_display_callback( $post ) {

    $value = get_post_meta( $post->ID, 'custom_column', true );

    echo '<textarea style="width:100%" id="custom_column" name="custom_column">' . esc_attr( $value ) . '</textarea>';
}

// For saving.
function save_shop_order_meta_box_data( $post_id ) {

    // If this is an autosave, our form has not been submitted, so we don't want to do anything.
    if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
        return;
    }

    // Check the user's permissions.
    if ( isset( $_POST['post_type'] ) && 'shop_order' == $_POST['post_type'] ) {
        if ( ! current_user_can( 'edit_shop_order', $post_id ) ) {
            return;
        }
    }

    // Make sure that it is set.
    if ( ! isset( $_POST['custom_column'] ) ) {
        return;
    }

    // Sanitize user input.
    $my_data = sanitize_text_field( $_POST['custom_column'] );

    // Update the meta field in the database.
    update_post_meta( $post_id, 'custom_column', $my_data );
}

add_action( 'save_post', 'save_shop_order_meta_box_data' );

//发件人::https://codex.wordpress.org/Plugin_API/Action_Reference/manage_posts_custom_column
//用于在列中显示。
添加过滤器('manage_edit-shop_order_columns','set_custom_edit_shop_order_columns');
函数集\自定义\编辑\车间\订单\列($columns){
$columns['custom_column']=uuu('custom column','your_text_domain');
返回$columns;
}
//将数据添加到订单投递类型的自定义列:
添加操作('manage_shop_order_posts_custom_column','custom_shop_order_column',10,2);
函数自定义\车间\订单\列($column,$post\u id){
开关($列){
案例“自定义_列”:
echo esc_html(get_post_meta($post_id,'custom_column',true));
打破
}
}
//用于在订单详细信息页面中显示和保存。
添加操作('add_meta_box'、'add_shop_order_meta_box');
函数add\u shop\u order\u meta\u box(){
添加元框(
“自定义_列”,
__(“自定义列”、“您的\u文本\u域”),
“店铺、订单、显示、回拨”,
“商店订单”
);
}
//用于显示。
功能车间\订单\显示\回拨($post){
$value=get\u post\u meta($post->ID,'custom\u column',true);
回显“”。esc_attr($value)。“”;
}
//为了节省。
函数save_shop_order_meta_box_data($post_id){
//如果这是自动保存,则我们的表单尚未提交,因此我们不想执行任何操作。
if(已定义('DOING_AUTOSAVE')&&DOING_AUTOSAVE){
返回;
}
//检查用户的权限。
如果(isset($\u POST['POST\u type'])和&“shop\u order'==$\u POST['POST\u type'])){
如果(!当前用户可以('edit_shop_order',$post_id)){
返回;
}
}
//确保它已设置。
如果(!isset($\u POST['custom\u column'])){
返回;
}
//清理用户输入。
$my_data=sanitize_text_字段($_POST['custom_column']);
//更新数据库中的元字段。
更新发布元数据($post\u id,$custom\u column',$my\u data);
}
添加操作('save_post'、'save_shop_order_meta_box_data');

使用订单编辑页面底部部分的默认自定义字段。我不确定我是否理解正确。我在订单编辑页面中没有看到任何自定义字段选项在订单编辑页面底部部分使用默认自定义字段您好,我不确定我是否理解正确。我在订单编辑页面中没有看到任何自定义字段选项哦,我在屏幕选项中关闭了它。我真傻!非常感谢。然而,从这个角度看,它们似乎与其他地方创建的现有值相关联,而不是创建一个新的值,例如courier\u reference。对不起,这可能是最基本的东西,但我正在学习