Open app/setup.php
, find the after_setup_theme
action and put add_theme_support('woocommerce');
inside the function.
Add the templates you want to override in resources/woocommerce
:
theme
│
└───resources
│
└───woocommerce
│ archive-product.php
│ single-product.php
│ ...
Inside each of the template overrides created in the previous step add the following code:
<?php echo App\Template('woo.template-name'); ?>
This assumues your blade is located at resources/views/woo/template-name.blade.php
, but the blades can be anywhere inside resources/views
.
Just write your blades like normal, adding the bits from the default plugin templates you want to keep.
@php if(!defined('ABSPATH')) { exit; } @endphp
@extends('layouts.app')
@section('content')
@while(have_posts())
@php the_post() @endphp
@include('woo.partials.single-product.content')
@endwhile
@php do_action('woocommerce_sidebar') @endphp
@endsection
If you want to use a default partial from the plugin use @php wc_get_template_part() @endphp
instead of @include
.
This was super helpful for me but I wasn't able to access any Controller data from within my blade template. I was able to achieve this by reducing the $data object based on the page classes and then passing that into the template.