简体   繁体   English

在 Woocommerce Checkout 页面中添加信息丰富的自定义消息

[英]Add an informative custom message in Woocommerce Checkout page

I have a WP/Woocommerce based website, and I would like to inform my clients that, whenever they buy something in my shop, the 3% of their order is devolved for charity associations.我有一个基于 WP/Woocommerce 的网站,我想通知我的客户,每当他们在我的店里买东西时,他们订单的 3% 都会交给慈善协会。

I would like to display the exact amount calculated on the total, for example: Total: 150 €我想显示按总金额计算的确切金额,例如:总金额:150 欧元

5 € will be devolved etc. 5 欧元将被转移等。

How can I manage it?我该如何管理?

You could display it as a Woocommerce "success" notice in checkout page, this way:您可以在结帐页面中将其显示为 Woocommerce“成功”通知,如下所示:

add_action( 'woocommerce_before_checkout_form', 'print_donation_notice', 10 );
function print_donation_notice() {
    wc_print_notice( sprintf(
        __("%s 3%% of this order will be devolved for charity associations, so an amount of %s.", "woocommerce"),
        '<strong>' . __("Information:", "woocommerce") . '</strong>',
        strip_tags( wc_price( WC()->cart->get_subtotal() * 0.03 ) )
    ), 'success' );
}

Code goes in function.php file of your active child theme (or active theme).代码位于活动子主题(或活动主题)的 function.php 文件中。 Tested and works.测试和工作。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM