Admin Side Add Option Select Specific One Product Using ACF Post Object Field [ Select Product Id in ACF Field ] (Mega Menu Porduct Shortcode )
/* Mega Menu Porduct Shortcode */
function mega_menu_product()
{
$product_id = get_field('select_mega_menu_product','option');
if(empty($product_id)) return;
ob_start();
$product = wc_get_product( $product_id );
$img = $product->get_image();
$product_link = get_permalink($product_id);
?>
<div class="cross-sells-box mega-menu-box">
<div class="cross-sells-wrapper">
<div class="cross-sells-left-image">
<a href="<?php echo $product_link; ?>">
<?php echo $img; ?>
</a>
</div>
<div class="cross-sells-right-content">
<div class="cross-sells-pro-title">
<a href="<?php echo $product_link; ?>">
<h4>
<?php echo $product->get_name(); ?>
</h4>
</a>
</div>
<div class="cross-sells-pro-desc">
<?php echo $product->get_short_description(); ?>
</div>
<div class="cross-sells-pro-price">
<?php echo $product->get_price_html(); ?>
<p>
<?php echo get_field('price_per_liter',$product_id); ?>
</p>
</div>
<div class="cross-sells-add-to-cart">
<a href="<?php echo $product_link; ?>" class="button">
Zum Produkt
</a>
</div>
</div>
</div>
</div>
<?php
return ob_get_clean();
}
add_shortcode( 'mega_menu_product' , 'mega_menu_product' );