Skip to content

Commit

Permalink
Fixed the payment method title
Browse files Browse the repository at this point in the history
  • Loading branch information
claudiosanches committed Jun 21, 2015
1 parent e7dfda1 commit d798d83
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions includes/class-wc-payment-discounts-add-discount.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ public function __construct() {
add_action( 'woocommerce_cart_calculate_fees', array( $this, 'add_discount' ), 10 );

// Display the discount in payment gateways titles.
add_filter( 'woocommerce_gateway_title', array( $this, 'gateway_title' ), 10, 2 );
add_filter( 'woocommerce_gateway_title', array( $this, 'payment_method_title' ), 10, 2 );

// Fix salved payment method title and update the cart discount total.
add_action( 'woocommerce_checkout_order_processed', array( $this, 'update_order_data' ), 10 );
}

/**
Expand Down Expand Up @@ -64,14 +67,18 @@ protected function discount_name( $value, $gateway ) {
}

/**
* Display the discount in gateway title.
* Display the discount in payment method title.
*
* @param string $title Gateway title.
* @param string $id Gateway ID.
*
* @return string
*/
public function gateway_title( $title, $id ) {
public function payment_method_title( $title, $id ) {
if ( ! is_checkout() && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
return $title;
}

$settings = get_option( 'woocommerce_payment_discounts' );

if ( isset( $settings[ $id ] ) && 0 < $settings[ $id ] ) {
Expand Down Expand Up @@ -124,6 +131,18 @@ public function add_discount( $cart ) {
}
}

/**
* Remove the discount in the payment method title.
*
* @param int $order_id Order ID.
*/
public function update_order_data( $order_id ) {
$payment_method_title = get_post_meta( $order_id, '_payment_method_title', true );
$new_payment_method_title = preg_replace( '/<small>.*<\/small>/', '', $payment_method_title );

// Save the new payment method title.
update_post_meta( $order_id, '_payment_method_title', $new_payment_method_title );
}
}

new WC_Payment_Discounts_Add_Discount();

1 comment on commit d798d83

@extrapixel
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was just about to create an issue regarding this... and here it is already ;) nice.

Please sign in to comment.