在 Woocommerce 的购物车页面顶部添加链接消息

Add a linked message at the top of cart page in Woocommerce

我想在购物车页面顶部的电子邮件订阅表单中添加 link。我有以下与购物车相关的模板:

如果我想要的是可能的,我是在其中一个代码中添加必要的代码,还是在我的 functions.php 中添加必要的代码?

如果您希望我复制任何这些模板的代码以回答问题,请告诉我。

您可以使用 WooCommerce wc_add_notice 功能在购物车页面上添加通知。

或移动子主题 'woocommerce' 文件夹中的购物车模板并自定义。

以下代码将在购物车页面顶部显示带有链接文本按钮的自定义消息:

add_action('woocommerce_before_cart', 'add_cart_custom_notice');
function add_cart_custom_notice() {
    // HERE the link to your content
    $link = '#';

    // For example, print a notice with a linked button (the text is editable and translatable)
    wc_print_notice( sprintf( '<span class="subscription-reminder">' .
        __('Pellentesque habitant morbi tristique senectus et netus et malesuada fames  %s', 'woocommerce') . '</span>',
        '<a href='.$link.' class="button alt" style="float:right">'. __('Go to the subscription form', 'woocommerce') .'</a>'
    ), 'notice' );
}

代码进入您的活动子主题(或活动主题)的 function.php 文件。已测试并有效。