in functions.php
<?php
function ShowCartOptionsById($atts){
extract( shortcode_atts(
array(
'id' => 1,
), $atts )
);
if ( $id && is_numeric($id) ) {
ob_start();
//woocommerce check
if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) { ?>
<div class="preview-block">
<?php
global $product;
$num = 0;
$merch = new WP_Query( array(
'p' => $id,
'post_type' => array( 'product' )
) );
if( $merch->have_posts() ) : while( $merch->have_posts() ) : $merch->the_post();
$product = get_product(); ?>
<?php
if($product->product_type == "variable"){
// echo '<div class="product-type-variable">';
woocommerce_variable_add_to_cart();
// echo '</div>';
} else {
woocommerce_quantity_input();
woocommerce_template_loop_add_to_cart();
} ?>
<?php endwhile; ?>
<?php endif; wp_reset_postdata(); ?>
</div><!--preview-block-->
<?php } } //woocommerce check?>
<?php return ob_get_clean(); }
add_shortcode( 'GetProductOptionsById', 'ShowCartOptionsById' );
if (!is_ssl()) {
$_SERVER['HTTPS'] = false;
}
?>