1

I'm trying to overwrite Woocommerce template files with the new Wordpress Sage. My problem is that the new Sage version with blade extension doesn't recognize old Woocommerce template files.

I used to copy the Woocommerce templates to my theme folder to overwrite the templates which always worked, but since the new Sage 9, this does not work anymore.

This is the Sage version I'm using: https://github.com/roots/sage (9)

This is the Woocommerce version I'm using: https://github.com/woocommerce/woocommerce (3.3.4)

Samuel Lelièvre
  • 3,212
  • 1
  • 14
  • 27
Thom van Oort
  • 43
  • 2
  • 4

3 Answers3

1

You can check https://github.com/mtx-z/Sage9-Woocommerce-Integration, up to date with Sage 9.0.1, Woocommerce 3.4.3 (this is mine).

I use it to use Sage features with a Woocommerce compatible theme.

Mtxz
  • 3,749
  • 15
  • 29
1

In your sage_theme/app/setup.php file add: add_theme_support('woocommerce'); with your soil theme supports.

In your sage_theme/resources/views folder create a woocommerce.blade.php file. Add the following code to this new file:

@php if ( !defined( 'ABSPATH' ) ) { exit; } @endphp

@extends( 'layouts.app' )

@section( 'content' )
    @if ( is_product() ) {{-- if single product --}}
        @php
            /**
            * woocommerce_before_main_content hook.
             *
            * @hooked woocommerce_output_content_wrapper - 10 (outputs opening divs for the content)
            * @hooked woocommerce_breadcrumb - 20
            */
            do_action( 'woocommerce_before_main_content' );
        @endphp

        @while ( have_posts() ) @php the_post(); @endphp

            @php wc_get_template_part( 'content', 'single-product' ); @endphp

        @endwhile

        @php
            /**
            * woocommerce_after_main_content hook.
            *
            * @hooked woocommerce_output_content_wrapper_end - 10 (outputs closing divs for the content)
            */
            do_action( 'woocommerce_after_main_content' );
        @endphp
    @else {{-- if product archive (any) --}}
        @if ( woocommerce_product_loop() ) 

            @php
                /**
                * Hook: woocommerce_before_shop_loop.
                *
                * @hooked woocommerce_output_all_notices - 10
                * @hooked woocommerce_result_count - 20
                * @hooked woocommerce_catalog_ordering - 30
                */
                do_action( 'woocommerce_before_shop_loop' );

                woocommerce_product_loop_start();
            @endphp

            @if ( wc_get_loop_prop( 'total' ) ) 
                @while ( have_posts() ) @php the_post(); @endphp

                    @php
                        /**
                        * Hook: woocommerce_shop_loop.
                        *
                        * @hooked WC_Structured_Data::generate_product_data() - 10
                        */
                        do_action( 'woocommerce_shop_loop' );

                        wc_get_template_part( 'content', 'product' );
                    @endphp
                @endwhile
            @endif

            @php
                woocommerce_product_loop_end();

                /**
                * Hook: woocommerce_after_shop_loop.
                *
                * @hooked woocommerce_pagination - 10
                */
                do_action( 'woocommerce_after_shop_loop' );
            @endphp
        @else
            @php
                /**
                * Hook: woocommerce_no_products_found.
                *
                * @hooked wc_no_products_found - 10
                */
                do_action( 'woocommerce_no_products_found' );
            @endphp
        @endif
    @endif
@endsection

Create a new folder in your sage_theme/resources/ folder called woocommerce. In that folder you need two files, archive-product.php and single-product.php. Both of those files should have: <?php echo App\Template('woocommerce'); ?> in them.

Now you're good to go.

All Woo traffic will filter through the sage_theme/resources/views/woocommerce.blade.php page, which is then pushing them to the sage_theme/resources/woocommerce folder where you can overwrite Woo template files as you normally do.

If you need to edit something that would normally be in archive-product.php or single-product.php you'll do that in the sage_theme/resources/views/woocommerce.blade.php file.

There might be a way, in sage_theme/resources/woocommerce/archive-product.php and sage_theme/resources/woocommerce/single-product.php to link to separate files instead of the same woocommerce.blade.php file, but I haven't had time to try it out yet.

Nick Hogan
  • 54
  • 1
  • 1
  • 10
0

First, try to put it in resources/woocommerce.

If that doesn't work, you may need to manually register the template path with Blade:

Add the following code to app/filters.php and update it to reference your WooCommerce path (resources/views/woocommerce/{your-template}.php) accordingly.

Compliments of @mmirus in the Roots forums for a similar question I posted there.

Disclaimer: I have not tested this yet and will this week. But the theory of registering it with Blade is correct.

Helpful links on the subject:

Spencer Hill
  • 1,043
  • 2
  • 15
  • 38