[Resolved] Automatic addition of commas to numbers in dynamic data

Home Forums Support [Resolved] Automatic addition of commas to numbers in dynamic data

Home Forums Support Automatic addition of commas to numbers in dynamic data

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #2177051
    Takeru

    Is there a way to automatically add commas to numbers in dynamic data?

    For example, I would like to display 1,000 instead of 1000.

    #2177060
    Fernando
    Customer Support

    Hi Marumoro,

    Thank you for reaching out to us here.

    As an example, I created a custom Post Meta field mymetaname: https://share.getcloudapp.com/NQuNYoLy

    I then created a Block Element with a Dynamic Headline Block as such: https://share.getcloudapp.com/04uEx2bJ

    Now, I added this code through plugin Code Snippets:

    add_filter( 'generate_dynamic_element_text', function( $my_post_meta, $block ){
    	if ( 'post-meta' === $block['attrs']['gpDynamicTextType']  && 'mymetaname' === $block['attrs']['gpDynamicTextCustomField']) {
    		$my_post_meta = number_format_i18n(floatval(get_post_meta(get_the_ID(),$block['attrs']['gpDynamicTextCustomField'])[0]));
    	} 
    	return $my_post_meta;
    },15,2);

    Here it is working on my site: https://share.getcloudapp.com/Z4u7jKlo

    Kindly replace mymetaname with your meta field name.

    Hope this helps! 🙂

    #2177079
    Takeru

    Perfect!
    Thank you very much.

    #2177088
    Fernando
    Customer Support

    You’re welcome Marumoro! Glad that worked. 🙂

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.