自定义checkout表单-login.php模板不显示按钮文本


Customizing checkout form-login.php template does not display button text

我想通过echo在php中显示一个链接,但问题是只有 class id 从我的 <a> 标签显示,但 data-toggle 不显示在网站上,链接不工作没有这个属性。

这是模板文件摘录的样子:

if ( is_user_logged_in() || 'no' === get_option( 'woocommerce_enable_checkout_login_reminder' ) ) {
    return;
}
$info_message  = apply_filters( 'woocommerce_checkout_login_message', __( 'Returning customer?', 'woocommerce' ) );
$info_message .= " <a href='"#modal-login'" class='"login'" data-toggle='"ml-modal'">" . __( 'Click here to login', 'woocommerce' ) . "</a>";
wc_print_notice( $info_message, 'notice' );

这是我浏览器中输出的源代码:

<a href="#modal-login" class="login">Klicke hier, um dich anzumelden.</a>

有人知道原因吗?

我已经在网上搜索了一个解决方案,但看起来我是唯一一个有这个问题的人。

谢谢。

似乎你正试图通过你的活动主题自定义 checkout/form-login.php WooCommerce模板的代码(这是官方相关文档:模板结构+通过主题覆盖模板)。

简单地说(如果还没有完成),你需要从woocommerce插件文件夹中复制一个名为 templates 的子文件夹到你的活动子主题(或主题),并将其重命名为 woocommerce 。之后,在 checkout 子文件夹的新 woocommerce 文件夹中发现一个名为 form-login.php 的模板。

这里是模板的完整代码,当您尝试这样做时,可以重新访问功能定制。打开/编辑 form-login.php 模板并将代码替换为:

<?php
/**
 * Checkout login form
 *
 * This template can be overridden by copying it to yourtheme/woocommerce/checkout/form-login.php.
 *
 * HOWEVER, on occasion WooCommerce will need to update template files and you
 * (the theme developer) will need to copy the new files to your theme to
 * maintain compatibility. We try to do this as little as possible, but it does
 * happen. When this occurs the version of the template file will be bumped and
 * the readme will list any important changes.
 *
 * @see         https://docs.woocommerce.com/document/template-structure/
 * @author      WooThemes
 * @package     WooCommerce/Templates
 * @version     2.0.0
 */
if ( ! defined( 'ABSPATH' ) ) {
    exit; // Exit if accessed directly
}
if ( is_user_logged_in() || 'no' === get_option( 'woocommerce_enable_checkout_login_reminder' ) ) {
    return;
}
$info_message  = apply_filters( 'woocommerce_checkout_login_message', __( 'Returning customer?', 'woocommerce' ) );
//////////////// HERE IS YOUR CUSTOMIZATION ///////////////
$info_message .= ' <a href="#modal-login" class="login" data-toggle="ml-modal">' . __( 'Click here to login', 'woocommerce' ) . '</a>';
wc_print_notice( $info_message, 'notice' );
?>
<?php
    woocommerce_login_form(
        array(
            'message'  => __( 'If you have shopped with us before, please enter your details in the boxes below. If you are a new customer, please proceed to the Billing &amp; Shipping section.', 'woocommerce' ),
            'redirect' => wc_get_page_permalink( 'checkout' ),
            'hidden'   => true
        )
    );
?>

然后保存。这次的输出应该与预期的一样。