Created
April 27, 2022 10:49
-
-
Save ipokkel/aad6e58fe99d32743d5057c313a1efe5 to your computer and use it in GitHub Desktop.
Change the display format of a price. This example will change the price format display to a French-Canadian format.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Change the display format of a price for a specific currency. | |
* | |
* You can add this recipe to your site by creating a custom plugin | |
* or using the Code Snippets plugin available for free in the WordPress repository. | |
* Read this companion article for step-by-step directions on either method. | |
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
*/ | |
function my_pmpro_french_canadian_price_format( $formatted, $price, $pmpro_currency, $pmpro_currency_symbol ) { | |
// Let's only do this for our specific currency | |
if ( 'CAD' === $pmpro_currency ) { | |
// Let's customize the display of the price | |
$new_price = number_format( $price, 0, null, ' ' ); | |
// Let's add the currency symbol as a postfix | |
$formatted = $new_price . ' ' . $pmpro_currency_symbol; | |
} | |
return $formatted; | |
} | |
add_filter( 'pmpro_format_price', 'my_pmpro_french_canadian_price_format', 20, 4 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment