php – 用自定义字符串替换Woocommerce优惠券金额
发布时间:2020-12-13 16:10:28 所属栏目:PHP教程 来源:网络整理
导读:目前在结帐页面和购物车页面后,人们应用优惠券代码然后购物车显示优惠券名称和从原始产品价格减少多少钱. 例如,产品价格为100,优惠券折扣为20%,然后显示优惠券名称,-20. 但我不想在那里显示-20,而是我需要在那里显示自定义字符串,如20%折扣.不是金额,而是
目前在结帐页面和购物车页面后,人们应用优惠券代码然后购物车显示优惠券名称和从原始产品价格减少多少钱.
例如,产品价格为100,优惠券折扣为20%,然后显示优惠券名称,-20. 但我不想在那里显示-20,而是我需要在那里显示自定义字符串,如20%折扣.不是金额,而是一些自定义字符串.. 我怎么能这样做? .当我搜索我可以找到那个主题/ woocommerce / cart / cart.php那里它正在使用一个函数<?php do_action('woocommerce_cart_collat??erals'); ?> .因此,没有选项可以编辑减少的金额. 所以请帮助,请注意这个字符串需要显示在结帐,购物车,订单电子邮件等. 解决方法
您需要使用woocommerce_cart_totals_coupon_html过滤器钩子,如下例所示:
add_filter( 'woocommerce_cart_totals_coupon_html','custom_cart_totals_coupon_html',30,3 ); function custom_cart_totals_coupon_html( $coupon_html,$coupon,$discount_amount_html ) { // For percent coupon types only if( 'percent' == $coupon->get_discount_type() ){ $percent = $coupon->get_amount(); // Get the coupon percentage number $discount_amount_html = '<span>' . $percent . ' % </span>'; // Formatting percentage // Replacing coupon discount,by custom percentage $coupon_html = $discount_amount_html . ' <a href="' . esc_url( add_query_arg( 'remove_coupon',urlencode( $coupon->get_code() ),defined( 'WOOCOMMERCE_CHECKOUT' ) ? wc_get_checkout_url() : wc_get_cart_url() ) ) . '" class="woocommerce-remove-coupon" data-coupon="' . esc_attr( $coupon->get_code() ) . '">' . __( '[Remove]','woocommerce' ) . '</a>'; } return $coupon_html; } 代码位于活动子主题(或活动主题)的function.php文件中.经过测试和工作. 它将用购物车和结账页面上的优惠券百分比替换折扣金额…… (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |