Loading WPBakery Content into WooCommerce Shop Page


So I am trying to allow a site admin to use Visual Composer/WPBakery to create content above the list of products on the WooCommerce Shop Page.

I can add the content easily enough, using the following code in my child theme’s functions.php:

//Add the_content() from Shop Page to before product listing.
add_action( 'woocommerce_before_shop_loop', 'ft_vc_shop_desc', 10 );

function ft_vc_shop_desc(){
    $shop_page = get_post( wc_get_page_id( 'shop' ) );
    if ( $shop_page ) {
        //$description = wc_format_content( $shop_page->post_content );
        $description = $shop_page->post_content ;
        $content = apply_filters( 'the_content', $description);

        // Load custom CSS from meta data
        $shortcodes_custom_css = get_post_meta($shop_page->ID, '_wpb_post_custom_css', true);

        // If custom CSS is provided, load inline style.
        if (!empty($shortcodes_custom_css)){
            $shortcodes_custom_css = strip_tags($shortcodes_custom_css);
            echo '<style type="text/css" data-type="vc_shortcodes-custom-css">';
                echo $shortcodes_custom_css;
            echo '</style>';
        if ( $description ) {
            // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
            echo '<div class="page-description">' . $content . '</div>';

The content loads in just fine, and any custom CSS added to the Page Settings load just fine too.

The problem is that it is not pulling in any settings from the Design tab of any row, column, block, etc.

Normally VC creates classes on elements using "vc_custom_[THE ELEMENT’S ID]", and adds tags that include styles referencing those classes.

Using my code above, the elements with custom Design tab styles do get these custom classes added, but the tag(s) don’t appear to be added.

Any thoughts on how to make this work? I haven’t had much luck.

Joe 2 years 2020-12-22T11:10:23-05:00 0 Answers 3 views 0

Leave an answer