Home Forums WoodMart support forum VC elements appear in terms & condition section of checkout page Reply To: VC elements appear in terms & condition section of checkout page

#124675

metuza
Participant

I have found a solution for this problem unless you have anything better.

Here is my solution which is added to child-theme functions:

// Remove shortcode tags from WC terms and conditions in checkout page
remove_action( 'woocommerce_checkout_terms_and_conditions', 'wc_terms_and_conditions_page_content', 30 );
add_action( 'woocommerce_checkout_terms_and_conditions', 'wc_terms_and_conditions_page_content_custom', 30 );
function wc_terms_and_conditions_page_content_custom() {
	$terms_page_id = wc_terms_and_conditions_page_id();
	if ( ! $terms_page_id ) {
		return;
	}
	$page = get_post( $terms_page_id );
	if ( $page && 'publish' === $page->post_status && $page->post_content && ! has_shortcode( $page->post_content, 'woocommerce_checkout' ) ) {
	echo '<div class="woocommerce-terms-and-conditions" style="display: none; max-height: 200px; overflow: auto;">' . wp_kses_post( wc_format_content(preg_replace( "~(?:\[/?)[^/\]]+/?\]~s", '', do_shortcode('[html_block id="20133"]') ) ) ) . '</div>';
	}
}

As i am using HTML blocks for the terms and conditions you will see in code that i call the block using shortcode. To call the page content directly just replace
do_shortcode('[html_block id="20133"]')
with this:
$page->post_content

Brgds
Rune