wordpress 自定义 Woocommerce 客户帐户页面

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18688843/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 19:20:51  来源:igfitidea点击:

Customize Woocommerce Customer Account Page

wordpresswoocommerce

提问by Karen

I am selling digital downloads on my Wordpress site using Woocommerce. I have been able to use a plugin to customize the checkout page so that customers only have to give their first and last names and email address to purchase a product. I would like the same thing to show on the Customer Informationpage and Edit My Addresspage and Accountpage.

我正在使用 Woocommerce 在我的 Wordpress 网站上销售数字下载。我已经能够使用插件来自定义结帐页面,这样客户只需提供他们的名字和姓氏以及电子邮件地址即可购买产品。我希望在“客户信息”页面、“编辑我的地址”页面和“帐户”页面上显示相同的内容。

Right now at the bottom of the Account page, it's calling information from the my-address.phppage. It calls Billing Address (First and Last Name) and Shipping Address, which doesn't show up because they have not been required to enter a shipping address.

现在在“帐户”页面的底部,它正在从my-address.php页面调用信息。它调用帐单地址(名字和姓氏)和送货地址,它们没有显示,因为他们不需要输入送货地址。

I would like the Billing Address to be "Name" and the Shipping Address to be "Email" and to have the person's email address to be called from my-address.php. I actually know how to change the Billing Address to Name. But I can't figure out how to change Shipping Address to Email and to have the person's email show up.

我希望帐单地址为“姓名”,送货地址为“电子邮件”,并希望从 呼叫此人的电子邮件地址my-address.php。我实际上知道如何将帐单地址更改为名称。但我不知道如何将送货地址更改为电子邮件并显示此人的电子邮件。

Does anyone have a clue how I could do this?

有谁知道我怎么能做到这一点?

Thanks for your time.

谢谢你的时间。

回答by Freney

If you copy the template files from the plugin directory to your theme (or child theme) directory, you can edit them to get what you want. The files in your theme directory will override the stock plugin template.

如果您将模板文件从插件目录复制到您的主题(或子主题)目录,您可以编辑它们以获得您想要的。主题目录中的文件将覆盖库存插件模板。

So the original templates are in plugins/woocommerce/templates/myaccount

所以原始模板在 plugins/woocommerce/templates/myaccount

Move the files you want to alter (probably just my-address.php, and/or my-account.php) to themes/my-theme/woocommerce/templates/myaccount/.

将您要更改的文件(可能只是my-address.php, 和/或my-account.php)移动到themes/my-theme/woocommerce/templates/myaccount/.

(NB: that's what the docs say, although I've found that the directory ought to be themes/my-theme/woocommerce/myaccount/—although that could be from conflicting plugins I also have installed.)

(注意:这就是文档所说的,尽管我发现该目录应该是themes/my-theme/woocommerce/myaccount/- 尽管这可能来自我也安装了冲突的插件。)

When you're editing the PHP file, the fields you're after are:

当您编辑 PHP 文件时,您需要的字段是:

$firstname = get_user_meta( $customer_id, 'billing_first_name', true );
$lastname = get_user_meta( $customer_id, 'billing_last_name', true );
$email = get_user_meta( $customer_id, 'billing_email', true );

The my-address.phpfile has an array that's similar:

my-address.php文件有一个类似的数组:

$address = apply_filters( 'woocommerce_my_account_my_address_formatted_address', array(
                'first_name'    => get_user_meta( $customer_id, $name . '_first_name', true ),
                'last_name'     => get_user_meta( $customer_id, $name . '_last_name', true ),
                'company'       => get_user_meta( $customer_id, $name . '_company', true ),
                'address_1'     => get_user_meta( $customer_id, $name . '_address_1', true ),
                'address_2'     => get_user_meta( $customer_id, $name . '_address_2', true ),
                'city'          => get_user_meta( $customer_id, $name . '_city', true ),
                'state'         => get_user_meta( $customer_id, $name . '_state', true ),
                'postcode'      => get_user_meta( $customer_id, $name . '_postcode', true ),
                'country'       => get_user_meta( $customer_id, $name . '_country', true )
            ), $customer_id, $name );

$namegets substituted as 'billing', so you can just change one of those address lines to '_email'if you like.

$name被替换为'billing',因此您可以根据需要将这些地址行之一更改为'_email'