woocommerce edit-account shortcode

2019-08-25 20:54发布

问题:

I saw in this question that is possible create a shortcode from my-orders page, I am trying create something similar to display the edit account page via shortcodes.

Reference: in woocommerce, is there a shortcode/page to view all orders?

function shortcode_my_orders( $atts ) {
    extract( shortcode_atts( array(
        'order_count' => -1
    ), $atts ) );

    ob_start();
    wc_get_template( 'myaccount/my-orders.php', array(
        'current_user'  => get_user_by( 'id', get_current_user_id() ),
        'order_count'   => $order_count
    ) );
    return ob_get_clean();
}
add_shortcode('my_orders', 'shortcode_my_orders');

回答1:

I created this shortcode to add the HTML contents of the Edit Account page in another page. I believe that's what you are asking for.

// Paste this in the function.php file of your active child theme or theme.
function wc_customer_edit_account_html_shortcode( $atts ) {

    // Attributes
    extract( shortcode_atts( array(
                'text' => 'Edit Account' ), $atts ) );

    return wc_get_template_html( 'myaccount/form-edit-account.php', array( 'user' => get_user_by( 'id', get_current_user_id() ) ) );;

}
add_shortcode( 'wc_customer_edit_account_html', 'wc_customer_edit_account_html_shortcode' );

You can also put this in a New Snippet in the Snippets plugin instead of editing the functions.php page.