Last active
April 12, 2022 10:31
-
-
Save skyshab/8d0992d38b2a7a0bf8f84b114c1ac747 to your computer and use it in GitHub Desktop.
Get cost description from block based event.
This file contains 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 | |
/** | |
* Get event cost description. | |
* | |
* @param $post_id - post id or post object. | |
* @return string | |
*/ | |
function get_cost_description( int $post_id = 0 ) { | |
$post = get_post( $post_id ); | |
if ( empty( $post->post_content ) ) { | |
return ''; | |
} | |
$blocks = parse_blocks( $post->post_content ); | |
$block_description = ''; | |
foreach( $blocks as $block ) { | |
if( 'tribe/event-price' === $block['blockName'] ) { | |
if ( isset( $block['attrs']['costDescription'] ) ) { | |
$block_description = $block['attrs']['costDescription']; | |
} | |
break; | |
} | |
} | |
return $block_description; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment