在其他人之前提出问题之后,我这里有一个问题:WooCommerce 结帐并自动登录后自动创建用户帐户
第一个问题:
在显示消息
(Thank you. Your order has been received. An account has been automatically created for you and you are now <a href="https://yoursite.name/my-account/">logged in< /a>.You will receive an email about this)
的此部分中,我应该如何显示创建的密码以及输入给客户的电子邮件? (此外,如果客户输入其他字段,例如名字和姓氏、电话号码等,也会显示在此处。)
第二个问题:
当我使用此代码时:
$link = get_permalink( get_option( 'woocommerce_myaccount_page_id' ) );
对我来说,它将链接的值显示为文本,也就是说,它看起来像这样:
Thank you. Your order has been received. An account has been automatically created for you and you are now <a href="https://yoursite.name/my-account/">logged in</a>. You will receive an email about this.
如何解决这个问题?登录值有一个链接 href 而不是显示为文本
主要问题是这些代码是否标准且是最新的?是否需要修改或更改它们以提高性能?
第一个问题:出于安全原因,您永远不会显示任何密码,并且会向客户发送电子邮件。除了结账字段中的信息外,客户没有输入任何其他内容,因此该信息已经显示。
第二个问题: 将第二个函数替换为:
add_filter( 'woocommerce_before_thankyou', 'filter_woocommerce_thankyou_order_received_text' );
function filter_woocommerce_thankyou_order_received_text( $order_id ) {
if ( is_user_logged_in() ) return;
$order = wc_get_order($order_id);
$order_email = $order->get_billing_email(); // Get the user email from the order
// Check if there are any users with the billing email as user or email
$email = email_exists( $order_email );
$user = username_exists( $order_email );
// If the UID is null, then it's a guest checkout (new user)
if ( $user == false && $email == false ) {
// Append to orginal string
wc_print_notice( sprintf(
__('An account has been automatically created for you and you are now %s. You will receive an email about this.', 'woocommerce'),
'<a href="' . get_permalink( get_option('woocommerce_myaccount_page_id') ) . '">logged in</a>'
), 'notice' );
}
}