I'm trying to create a WooCommerce shortcode to display one product with some information.
Every day there is a new product with attribute DAGAANBIEDING and value JA or NEE.
I only want to show that product with value JA.
The shortcode is working but nothing is displaying.
This is what I have:
//custom shortcodes
if( !function_exists('product_snippet') ) {
function product_snippet( $atts ) {
// Attributes
extract( shortcode_atts(
array(
'taxonomy' => 'pa_dagaanbieding', // You will use $id to get the value of this attribute
'terms' => 'Ja' // You will use $snippet to get the value of this attribute
),
$atts
));
// Get an instance of the product object
$product = wc_get_product( $id );
// Displays go here
return '<div class="row">
<div class="col-md-6"><h3>'.$product->get_title().'</h3>'.$product->get_image().'<br><br><a href="'.get_permalink( $id ).'"><button type="submit" class="single_add_to_cart_button button alt">Bekijk aanbieding</button></a></div>
<div class="col-md-6">'.$product->get_regular_price().' '.$product->get_regular_price().'</div>
</div>';
}
add_shortcode( 'product_snippet', 'product_snippet' );
}
But it does not show information.