首页 > 解决方案 > 保存在 Wordpress 用户配置文件中的新字段

问题描述

我在使用 Wocommerce 发送购买时创建的所有用户的个人资料中创建了一个额外的字段:

add_action( 'show_user_profile', 'extra_user_profile_fields' );
add_action( 'edit_user_profile', 'extra_user_profile_fields' );

function extra_user_profile_fields( $user ) { ?>
    <h3>Extra profile information</h3>
    <table class="form-table">
        <tr>
            <th><label for="DNI"></label></th>
            <td>
                <input type="text" name="dni" id="dni" value="<?php echo esc_attr( get_the_author_meta( 'dni', $user->ID ) ); ?>" class="regular-text" /><br/>
                <span class="description">DNI</span>
            </td>
        </tr>
    </table>
<?php }

要保存它:

add_action( 'personal_options_update', 'save_extra_user_profile_fields' );
    add_action( 'edit_user_profile_update', 'save_extra_user_profile_fields' );

    function save_extra_user_profile_fields( $user_id ) {
        if ( !current_user_can( 'edit_user', $user_id ) ) { 
            return false; 
        }
        update_user_meta( $user_id, 'dni', $_POST['dni'] );
    }

我还使用插件“结帐字段编辑器”在 Wocommerce 购买表单中创建了一个额外的字段。

现在我想链接这些字段,并且在进行购买时输入的值保存在配置文件中创建的值中。

可能吗?

标签: javascriptphpwordpresswoocommerce

解决方案


推荐阅读