Php 在Woocommerce中的单个产品页面上显示优惠券代码
我想在woocommerce的每个产品页面上显示折扣优惠券,原因有两个Php 在Woocommerce中的单个产品页面上显示优惠券代码,php,wordpress,woocommerce,product,coupon,Php,Wordpress,Woocommerce,Product,Coupon,我想在woocommerce的每个产品页面上显示折扣优惠券,原因有两个 很多新客户忽略了主页和网站标题上提到的折扣券,尽管我是出于好意 有了折扣券,我想鼓励更多的用户预付货款,避免货到付款 这有可能实现吗?更新:添加了购物车挂钩页面 这可以通过以下简单操作完成,即在单个产品页面中添加带有优惠券代码的自定义通知消息: add_action( 'woocommerce_before_single_product', 'custom_message_before_single_product', 5
这有可能实现吗?更新:添加了购物车挂钩页面 这可以通过以下简单操作完成,即在单个产品页面中添加带有优惠券代码的自定义通知消息:
add_action( 'woocommerce_before_single_product', 'custom_message_before_single_product', 5 ); // For single product page
add_action( 'woocommerce_before_cart', 'custom_message_before_single_product'); // For cart page
function custom_message_before_single_product() {
$coupon_code = 'special10';
wc_print_notice( sprintf(
__("You get %s when using credit card payment with the %s coupon code.", "woocommerce"),
'<strong>' . __("a 10% discount", "woocommerce") . '</strong>',
'<code>' . $coupon_code . '</code>'
), 'notice' );
}
代码进入活动子主题(或活动主题)的function.php文件。测试和工作
您将在单个产品页面中看到类似的内容:
add_action( 'woocommerce_before_single_product', 'custom_message_before_single_product', 5 ); // For single product page
add_action( 'woocommerce_before_cart', 'custom_message_before_single_product'); // For cart page
function custom_message_before_single_product() {
$coupon_code = 'special10';
wc_print_notice( sprintf(
__("You get %s when using credit card payment with the %s coupon code.", "woocommerce"),
'<strong>' . __("a 10% discount", "woocommerce") . '</strong>',
'<code>' . $coupon_code . '</code>'
), 'notice' );
}
很抱歉再次打扰您,但我想知道购物车页面是否也会显示相同的消息?