2 php wordpress cart coupon woocommerce
在阅读完woocommerce_add_$NOTICE_TYPE钩子后,我不确定我是否正确地做到了这一点。我想要做的是将Coupon code applied successfully消息更改为我自己的自定义文本,如下所示:
The %coupon_name% promotion code has been applied and redeemed successfully.
Run Code Online (Sandbox Code Playgroud)
但我不知道如何获得优惠券名称。
add_filter( 'woocommerce_add_notice', function( $message ){
// get the coupon name here
if( $message == 'Coupon code applied successfully.' )
$message = 'The %coupon_name% promotion code has been applied and redeemed successfully.';
return $message;
});
Run Code Online (Sandbox Code Playgroud)
应用或删除优惠券代码时,有一个特定的“成功”通知挂钩:
add_filter( 'woocommerce_coupon_message', 'filter_woocommerce_coupon_message', 10, 3 );
function filter_woocommerce_coupon_message( $msg, $msg_code, $coupon ) {
// $applied_coupons = WC()->cart->get_applied_coupons(); // Get applied coupons
if( $msg === __( 'Coupon code applied successfully.', 'woocommerce' ) ) {
$msg = sprintf(
__( "The %s promotion code has been applied and redeemed successfully.", "woocommerce" ),
'<strong>' . $coupon->get_code() . '</strong>'
);
}
return $msg;
}
Run Code Online (Sandbox Code Playgroud)
代码位于活动子主题(或活动主题)的 functions.php 文件中。测试和工作。
| 归档时间: |
|
| 查看次数: |
2310 次 |
| 最近记录: |