Skip to content

Instantly share code, notes, and snippets.

@skyshab
Last active April 12, 2022 10:31
Show Gist options
  • Save skyshab/8d0992d38b2a7a0bf8f84b114c1ac747 to your computer and use it in GitHub Desktop.
Save skyshab/8d0992d38b2a7a0bf8f84b114c1ac747 to your computer and use it in GitHub Desktop.
Get cost description from block based event.
<?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