i'm trying to solve a problem with get_template_part()
and some code that i need to include
I create a first file with some code and include this with the function get_template_part()
and this work correctly, but when a try with a second part of code in another file, this generate an error.
THE CODE INSIDE FILE:
<div class="container padding-100-top-bottom main-padding-mobile">
<div class="row padding-50-bottom">
<div class="col-sm-12">
<h1 class="animated fadeInUp">Los mejores tours de Roma</h1>
<h5 class="animated fadeInUp" style="font-weight: 400;">Ver todos los tours <i class="gdlr-core-pos-right fa fa-long-arrow-right" style="font-size: 17px ; margin-left: 10px;"></i></h5>
</div>
</div>
<div class="row">
<?php
// Setup your custom query
$args = array(
'post_type' => 'product',
'posts_per_page' => 6,
);
$loop = new WP_Query($args);
while ($loop->have_posts()) : $loop->the_post(); ?>
<div class="col-sm-6 col-md-6 col-lg-4 animated fadeInUp">
<div class="card" style="margin-bottom: 30px;">
<div class="sezione_home_tours_img" style="background-image: url('<?php echo get_the_post_thumbnail_url(); ?>');">
</div>
<div class="card-body">
<h5 class="card-title"><?php the_title(); ?></h5>
<div class="contenitore_info_card">
<ul>
<li><i class="fas fa-map-signs"></i> <?php the_field('start_from'); ?></li>
<li><i class="far fa-clock"></i> <?php the_field('duration'); ?></li>
</ul>
<div class="sezione_home_tours_card_prezzo">
<h6>A partir de</h6>
<h3><?php echo $product->get_price_html(); ?></h3>
</div>
</div>
</div>
</div>
</div>
<?php endwhile; wp_reset_query(); // Remember to reset?>
</div>
</div>
THE ERROR GENERATED:
error: Uncaught Error: Call to a member function get_price_html() on null in /app/public/wp-content/themes/transportes-child/template-parts/home-sezione-roma.php:33 Stack trace: #0 /app/public/wp-includes/template.php(724): require()
1 /app/public/wp-includes/template.php(671): load_template('/app/public/wp-...', false) #2
/app/public/wp-includes/general-template.php(168): locate_template(Array, true, false) #3 /app/public/wp-content/themes/transportes-child/page-template/home.php(19): get_template_part('template-parts/...', 'sezione-roma') #4 /app/public/wp-includes/template-loader.php(78): include('/app/public/wp-...') #5 /app/public/wp-blog-header.php(19): require_once('/app/public/wp-...') #6 /app/public/index.php(17): require('/app/public/wp-...') #7 {main} thrown in /app/public/wp-content/themes/transportes-child/template-parts/home-sezione-roma.php on line 33