WooCommerce: aggiungere una sezione al profilo utente

WooCommerce: aggiungere una sezione al profilo utente

In WooCommerce è semplice aggiungere una nuova sezione al profilo utente.

Supponendo che lo slug della nuova sezione da aggiungere sia nuova-sezione, possiamo aggiungere il seguente codice al file functions.php del nostro tema o al codice del nostro plugin ricordandoci però di salvare nuovamente i permalink a lavoro ultimato.


function my_add_wc_profile_endpoint() {
    add_rewrite_endpoint( 'nuova-sezione', EP_ROOT | EP_PAGES );
}

add_action( 'init', 'my_add_wc_profile_endpoint', 9999 );

function my_add_wc_profile_query_var( $vars ) {
    $vars[] = 'nuova-sezione';
    return $vars;
}

add_filter( 'query_vars', 'my_add_wc_profile_query_var', 0 );

function my_add_wc_profile_link( $items ) {
    $items['nuova-sezione'] = __( 'Nuova sezione', 'textdomain' );
    return $items;
}

add_filter( 'woocommerce_account_menu_items', 'my_add_wc_profile_link' );

function my_add_wc_profile_html_content() {
    $html = '<h1>' . __( 'Nuova sezione', 'textdomain' ) . '</h1>';
    echo $html;
}

add_action( 'woocommerce_account_nuova-sezione_endpoint', 'my_add_wc_profile_html_content' );

Torna su