@@ -213,6 +213,7 @@ public static function enqueue_block_editor_assets() {
213
213
'custom_taxonomies ' => self ::get_custom_taxonomies (),
214
214
'can_use_name_your_price ' => self ::can_use_name_your_price (),
215
215
'tier_amounts_template ' => self ::get_formatted_amount (),
216
+ 'currency ' => function_exists ( 'get_woocommerce_currency ' ) ? \get_woocommerce_currency () : 'USD ' ,
216
217
];
217
218
218
219
if ( class_exists ( 'WP_REST_Newspack_Author_List_Controller ' ) ) {
@@ -1414,13 +1415,13 @@ public static function get_article_meta_footer( $post = null ) {
1414
1415
/**
1415
1416
* Get a formatted HTML string containing amount and frequency of a donation.
1416
1417
*
1417
- * @param float $amount Amount.
1418
- * @param string $frequency Frequency.
1419
- * @param bool $hide_once_label Whether to hide the "once" label.
1418
+ * @param float|string $amount Amount.
1419
+ * @param string $frequency Frequency.
1420
+ * @param bool $hide_once_label Whether to hide the "once" label.
1420
1421
*
1421
1422
* @return string
1422
1423
*/
1423
- public static function get_formatted_amount ( $ amount = 0 , $ frequency = 'day ' , $ hide_once_label = false ) {
1424
+ public static function get_formatted_amount ( $ amount = ' AMOUNT_PLACEHOLDER ' , $ frequency = 'day ' , $ hide_once_label = false ) {
1424
1425
if ( ! function_exists ( 'wc_price ' ) || ( method_exists ( 'Newspack\Donations ' , 'is_platform_wc ' ) && ! \Newspack \Donations::is_platform_wc () ) ) {
1425
1426
if ( 0 === $ amount ) {
1426
1427
return false ;
@@ -1432,23 +1433,22 @@ public static function get_formatted_amount( $amount = 0, $frequency = 'day', $h
1432
1433
$ formatted_price = '<span class="price-amount"> ' . $ formatter ->formatCurrency ( $ amount , 'USD ' ) . '</span> <span class="tier-frequency"> ' . $ frequency_string . '</span> ' ;
1433
1434
return str_replace ( '.00 ' , '' , $ formatted_price );
1434
1435
}
1436
+
1437
+ // Format the amount with currency symbol and separators.
1438
+ $ amount_string = \wc_price (
1439
+ $ amount ,
1440
+ [ 'decimals ' => is_int ( $ amount ) ? 0 : 2 ]
1441
+ );
1442
+
1435
1443
if ( ! function_exists ( 'wcs_price_string ' ) ) {
1436
- return \wc_price ( $ amount ) ;
1444
+ return $ amount_string ;
1437
1445
}
1438
1446
$ price_args = [
1439
- 'recurring_amount ' => $ amount ,
1447
+ 'recurring_amount ' => $ amount_string ,
1440
1448
'subscription_period ' => 'once ' === $ frequency ? 'day ' : $ frequency ,
1441
1449
];
1442
1450
$ wc_formatted_amount = \wcs_price_string ( $ price_args );
1443
1451
1444
- // A '0' value means we want a placeholder string to replace in the editor.
1445
- if ( 0 === $ amount ) {
1446
- preg_match ( '/<\/span>(.*)<\/bdi>/ ' , $ wc_formatted_amount , $ matches );
1447
- if ( ! empty ( $ matches [1 ] ) ) {
1448
- $ wc_formatted_amount = str_replace ( $ matches [1 ], 'AMOUNT_PLACEHOLDER ' , $ wc_formatted_amount );
1449
- }
1450
- }
1451
-
1452
1452
// A 'day' frequency means we want a placeholder string to replace in the editor.
1453
1453
if ( 'day ' === $ frequency ) {
1454
1454
$ wc_formatted_amount = preg_replace ( '/ \/ ?.*/ ' , 'FREQUENCY_PLACEHOLDER ' , $ wc_formatted_amount );
0 commit comments