• I’m using the newest Sage starter theme (version 9) from Roots and it comes with Laravel Blade templating engine.

    So my problem now is that when I use single-product.blade.php to modify my product page layout it doesn’t load add-to-cart-variation.js when browsing variable products. So I’m unable to update price and stock qty based on selection.

    Does anyone know what is the logic behind including that javascript or how the variable product is loaded?

    Everything works as expected with the same markup if I use single-product.php instead of single-product.blade.php

    base.blade.php

    `<!doctype html>
    <html @php language_attributes(); @endphp >

    @include(‘partials/head’)

    <body @php body_class(); @endphp >

    @include(‘partials/header’)

    <main class=”main” role=”document”>
    @yield(‘content’)
    </main>

    @include(‘partials/footer’)
    @php wp_footer(); @endphp

    </body>
    </html>`

    single-product.blade.php:

    `@extends(‘layouts.base’)
    @section(‘content’)

    <section id=”single-product” class=”container”>

    {{– Breadcrumbs –}}
    @include(‘partials/breadcrumb’)

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

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

    @endwhile

    </section>

    @endsection`

    And here is the working single-product.php:

    `<!DOCTYPE html>
    <html>
    <!– HEAD –>
    <?php echo App\Template(‘partials/head’); ?>

    <body <?php body_class(); ?>>

    <!– HEADER –>
    <?php echo App\Template(‘partials/header’); ?>

    <!– CONTENT –>
    <main class=”main” role=”document”>
    <section id=”single-product” class=”container”>

    <!– Breadcrumbs –>
    <?php echo App\Template(‘partials/breadcrumb’); ?>

    <?php while ( have_posts() ) : the_post(); ?>

    <?php wc_get_template_part( ‘content’, ‘single-product’ ); ?>

    <?php endwhile; // end of the loop. ?>

    </section>

    </main>

    <!– FOOTER –>
    <?php echo App\Template(‘partials/footer’); ?>
    <?php wp_footer(); ?>

    </body>
    </html>`

    I have also tried to enqueue the script inside the theme functions.php but it doesn’t work (script is included but the variation selection does not update price nor stock quantity).

    Any help is appreciated!

    • This topic was modified 7 years, 10 months ago by eljass.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi, I have also been trying to use woocommerec working with sage 9 and have tried different options. Could you post the file hierarchy of the theme structure and where you have placed the woocommerce related files. There were couple of suggestions on roots forum. I believe you have also commented in this thread. Roots forum. I could not get the archive-product.blade.php or single-product.blade.php working. They only worked without ..’blade’… any suggestion.

    Thanks

    Thread Starter eljass

    (@eljass)

    Hey!

    I have managed to get blade template working by adding both blade and php files.

    All my woocommerce template files are inside theme/template/woocommerce

    Ie. archive-product.php should have the following:

    <?php echo App\Template('woocommerce/archive-product');

    This will use template function from theme/src/helper.php

    This way you can use blade syntax with woocommerce pretty easily.

    Also some template files will need some variables that woocommerce pass to the template. In this case just use template function like this:

    
    <?php echo App\Template('template-file-name', array('variable' => $variable) );

    This may not be the most efficient way to do this job since you have to have two files for one template but atleast it works.

    Check here for some extra information: https://github.com/roots/sage/issues/1807

    • This reply was modified 7 years, 9 months ago by eljass. Reason: Typo fixes
    Markus

    (@markushenriksson)

    Did you solve this? I managed to bypass it by adding this to setup.php:

    wp_enqueue_script( 'wc-add-to-cart-variation', $woocommerce->plugin_url() . '/assets/js/frontend/add-to-cart-variation.js', array('jquery'), '1.6', true );

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘WooCommerce add-to-cart-variation.js not including’ is closed to new replies.