将“保存更改”按钮添加到新的Woocommerce我的帐户页面

时间:2018-10-15 14:04:24

标签: php wordpress woocommerce

我目前正在尝试使用action_woocommerce_save_account_details函数中的新按钮“ Save Changes”从iconic_print_user_frontend_fields中保存$ value。但是现在,我只显示带有保存更改的回显。知道我该怎么做吗?

/**
 * Add fields to account area.
 */
function iconic_print_user_frontend_fields() {
    $fields            = iconic_get_account_fields();
    $is_user_logged_in = is_user_logged_in();

    foreach ( $fields as $key => $field_args ) {
        $value = null;

        if ( ! iconic_is_field_visible( $field_args ) ) {
            continue;
        }

        if ( $is_user_logged_in ) {
            $user_id = iconic_get_edit_user_id();
            $value   = iconic_get_userdata( $user_id, $key );
        }

        $value = isset( $field_args['value'] ) ? $field_args['value'] : $value;

        woocommerce_form_field( $key, $field_args, $value );
    }
}

add_action('woocommerce_my_new_endpoint', 'iconic_print_user_frontend_fields', 10);enter code here

// define the woocommerce_save_account_details callback 
function action_woocommerce_save_account_details() {    
        echo 'Save Changes!';
}; 

// add the action 
add_action( 'woocommerce_my_new_endpoint', 'action_woocommerce_save_account_details', 10, 1 );

在后端正常工作。

/**
 * Add fields to admin area.
 */
function iconic_print_user_admin_fields() {
    $fields = iconic_get_account_fields();
    ?>
    <h2><?php _e( 'My additional Fields', 'iconic' ); ?></h2>
    <table class="form-table" id="iconic-additional-information">
        <tbody>
        <?php foreach ( $fields as $key => $field_args ) { ?>
            <?php
            if ( ! iconic_is_field_visible( $field_args ) ) {
                continue;
            }

            $user_id = iconic_get_edit_user_id();
            $value   = get_user_meta( $user_id, $key, true );
            ?>
            <tr>
                <th>
                    <label for="<?php echo $key; ?>"><?php echo $field_args['label']; ?></label>
                </th>
                <td>
                    <?php $field_args['label'] = false; ?>
                    <?php woocommerce_form_field( $key, $field_args, $value ); ?>
                </td>
            </tr>
        <?php } ?>
        </tbody>
    </table>
    <?php
}

add_action( 'show_user_profile', 'iconic_print_user_admin_fields', 30 ); // admin: edit profile
add_action( 'edit_user_profile', 'iconic_print_user_admin_fields', 30 ); // admin: edit other users

0 个答案:

没有答案