Skip to content

Instantly share code, notes, and snippets.

@rameshelamathi
Last active February 9, 2019 11:24
Show Gist options
  • Save rameshelamathi/8d43d70bb0079a65ce88a9a43bcd4e29 to your computer and use it in GitHub Desktop.
Save rameshelamathi/8d43d70bb0079a65ce88a9a43bcd4e29 to your computer and use it in GitHub Desktop.
Change coupon label in WooCommerce
//The following snippet will be useful when you want to display the rule name instead of the standard Coupon: Discount
//while using the Woo Discount Rules plugin
if(!function_exists('woo_applied_cart_rules')) {
function woo_applied_cart_rules($cart_rules_object){
global $applied_rules;
$applied_rules = array();
if(isset($cart_rules_object->matched_discounts)) {
global $applied_rules;
$applied_rules = $cart_rules_object->matched_discounts;
}
}
}
add_action('woo_discount_rules_after_fetching_discount', 'woo_applied_cart_rules', 10, 1);
if(!function_exists('fc_woo_applied_coupons_in_cart')) {
function fc_woo_applied_coupons_in_cart($text, $code) {
//process only for woo discount rules
if(isset($code->code) && $code->code == 'discount') {
global $applied_rules;
$rule_names = '';
if(isset($applied_rules) && count($applied_rules) && isset($applied_rules['name']) ) {
$rule_names = implode(', ', $applied_rules['name']);
}
if(!empty($rule_names)) {
//change the value here to have your own customized display
$text = 'Discounts applied ('.$rule_names.')';
}
}
return $text;
}
}
add_filter('woocommerce_cart_totals_coupon_label', 'fc_woo_applied_coupons_in_cart', 10, 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment