Variable Visions

Wordpress and Woocommerce widget for inserting PHP in Elementor

Published Tue. Mar. 03, 2020

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 class="elementor-container clickour">
<div class="woocommerce elementor-container" style="padding-top: 0px;">
<ul class="products columns-4" style="width: 100%;">
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'posts_per_page' => 100,
'orderby' => 'menu_order',
'order' => 'ASC',
'tax_query' => array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => array('gaskets', 'clamps', 'o-rings'),
'operator' => 'IN',
'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
} else {
echo __( 'No products found' );