Skip to content

Commit

Permalink
fix: remove the cents for prices over 3 digits
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelpeixe committed Jan 16, 2024
1 parent 700170f commit 3c0981a
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion includes/class-modal-checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,12 +311,19 @@ public static function render_modal_markup() {
}

/**
* Update product price string for subscriptions to use "per" instead of "/".
* Update product price string for subscriptions to use "per" instead of "/"
* and remove the cents when the price is over 3 digits.
*
* @param string $price_string The price string.
*/
public static function update_subscriptions_product_price_string( $price_string ) {
$price_string = str_replace( ' / ', ' ' . __( 'per', 'newspack-blocks' ) . ' ', $price_string );
// For prices over 3 digits and 00 cents, remove the cents.
$pattern = '/\b\d{3,}\.\d{2}\b/';
preg_match( $pattern, $price_string, $matches );
if ( ! empty( $matches ) ) {
$price_string = preg_replace( $pattern, preg_replace( '/\.00$/', '', $matches[0] ), $price_string );
}
return $price_string;
}

Expand Down

0 comments on commit 3c0981a

Please sign in to comment.