우커머스 – 상품 가격 표시 숏코드

특정 우커머스 상품의 가격 정보를 보여줘야 하거나, 별도 레이아웃 빌더 사용시 우커머스 가격이 필요한경우 별도 숏코드를 제작해서 상품 가격을 노출할수 있습니다. 아래 코드를 사용하시는 테마 functions.php 에 추가 하신후, 가격을 표시하고 싶은 위치에 [danbi_wc_price]라는 숏코드를 넣습니다.
<?php
add_shortcode( 'danbi_wc_price', function($atts){
       global $post;

       $atts = shortcode_atts( array(
                     'id' => $post->ID,
       ), $atts );

       $output = '';

       if( intval( $atts['id'] ) > 0 && function_exists( 'wc_get_product' ) ){
              ob_start();
               $_product = wc_get_product( $atts['id'] );
               if ( $price_html = $_product->get_price_html() ){
                      ?>
                      <span class="price"><?php echo $price_html; ?></span>
                      <?php
               }
               $output = ob_get_clean();
       }
       return $output;
});