After adding some custom PHP to the Woocommerce home page file, I wanted to use some of the same PHP within an Elementor widget. I had a few issues with certain plugins not parsing the PHP correctly when not logged in, I eventually used 'PHP Everywhere' plug
I then placed this type of PHP on a page, with the PHP Widget.
I'm using this to show a list of products of a certain attribute on any page/widget
<div class="featuredcategorycontainer elementor-section elementor-section-boxed"><div class="elementor-container" style="padding-top: 20px;">
</div>
<div class="elementor-container clickour">
</div>
<div class="woocommerce elementor-container" style="padding-top: 0px;">
<ul class="products columns-4" style="width: 100%;">
<?php
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'posts_per_page' => 100,
'orderby' => 'menu_order',
'order' => 'ASC',
'tax_query' => array(
array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => array('gaskets', 'clamps', 'o-rings'),
'operator' => 'IN',
),
array(
'taxonomy' => 'pa_material',
'field' => 'slug',
'terms' => 'buna-n',
'operator' => 'IN'
),
),
);
$loop = new WP_Query( $args );
if ( $loop->have_posts() ) {
while ( $loop->have_posts() ) : $loop->the_post();
echo '<li class="product-category product"><a href="'.get_the_permalink().'"><div>'.get_the_post_thumbnail().'</div><h3 style="width: 80%; margin: 0
auto;">'.get_the_title().'</h3></a></li>';
endwhile;
} else {
echo __( 'No products found' );
}
wp_reset_postdata();
?>
</ul>
</div>
</div>