吴商务编辑帐户快捷代码根本不起作用


Woo-commerce edit account shortcode not working at all

我们使用的Wooccommerce当前版本是2.5.5,我在编辑帐户页面中使用以下快捷代码。

[woocommerce_edit_account]

但是,我的页面显示主页,而不是编辑帐户页面。现在有什么新鲜事吗?

它们不再工作,它们只适用于Wooccommerce 2.1或更低版本。它们已经被端点取代,所以你需要做这样的事情:

$my_account_link = get_permalink( get_option('woocommerce_myaccount_page_id') );
$edit_acount_link = $my_account_link . '/edit-account';

如果第一行太长,请尝试以下操作:

$my_account_link = get_bloginfo('url'). '/my-account';

您可以在以下位置阅读有关端点的详细信息:https://docs.woothemes.com/document/woocommerce-endpoints-2-1/

您可以使用本机WooCommerce函数wc_customer_edit_account_url()
(它也用于wooccommerce my_account.php模板)

正如Skatox所提到的,[woocommerce_edit_account]不再工作。

您可以将其与自定义的自动关闭快捷代码一起使用:

// Paste this in the function.php file of your active child theme or theme.
function wc_customer_edit_account_shortcode( $atts ) {
    // Attributes
    $atts = shortcode_atts(
        array(
            'text' => '',
        ),
    );
    return '<a class="customer-edit-account" href="'.wc_customer_edit_account().'">'.$text.'</a>';
}
add_shortcode( 'wc_customer_edit_account', 'wc_customer_edit_account_shortcode' );

使用:[wc_customer_edit_account text="Editing my account details" /]

在我的网站上(使用WooCommerce 3.6.5),这是适用于我的代码:

// Paste this in the function.php file of your active child theme or theme.
function wc_customer_edit_account_shortcode( $atts ) {
    // Attributes
    extract( shortcode_atts( array(
                'text' => 'Edit Account' ), $atts ) );
    return '<a class="customer-edit-account" href="'.wc_customer_edit_account_url().'">'.$text.'</a>';
}
add_shortcode( 'wc_customer_edit_account', 'wc_customer_edit_account_shortcode' );

我没有编辑function.php,甚至没有添加子主题,而是使用Snippets插件将其粘贴到一个新的Snippet中。