Detect what shortcode is being used in WordPress

This is a WordPress question.

I’m wondering, how would you create a function that detect if WooCommerce wants to output itself?

So on my page.blade.php file, I’m using ACF with flexbile content, so when WooCommerce wants to output a shortcode, it can’t.

How do I find all woocommerce_* shortcodes, and let them echo out?

I want to detect if woocommerce is trying to output shortcode and then output it, if not, just keep using the above code, flexbile content.

So far I got this:

@php($count = 0)

    @if ( have_rows( 'flexible_content' ) ) 

    @while ( have_rows( 'flexible_content' ) ) @php(the_row())

        <section>

        {{-- <x-section container="{{ $page[$count]['container'] }}" paddingTop="{{ $page[$count]['paddingTop']}}" paddingBottom="{{ $page[$count]['paddingBottom']}}" bgColor="{{ $page[$count]['backgroundColor'] }}"> --}}

        @if ( have_rows( 'row' ) )

        @while ( have_rows( 'row' ) ) @php(the_row())

    

            @if ( have_rows( 'column' ) )

            @while ( have_rows( 'column' ) ) @php(the_row())

            

                @php($layoutConverted = str_replace( '_', '-', get_row_layout()))

                

                @include('blocks.' . $layoutConverted)

            

            @endwhile

            @endif

                    

        @endwhile

        @endif

        </section>

        {{-- </x-section> --}}

    @php($count++)

    @endwhile

    @elseif(true)  

    {{-- check if it has shortcode of: woocommerce_* , if yes, display it --}}

         @php(the_content())

    @else

        <h3>No matching template found - page.blade.php

    @endif

Why not create a my-account custom page template that just has do_shortcode( 'whatever_the_shortcode_is' ) in the template, and then assign that page template to the page you want to use for the my-account thing?

That’ll get daunting very fast with multiple pages like that. I know you can create a page in WP and then output the shortcode via the same loop but I feel thats daunting and kinda dirty in this case.

This topic was automatically closed after 42 days. New replies are no longer allowed.