duanpanzhu2910 2019-03-27 12:29
浏览 76

将Woocommerce格式的产品价格添加到主题的产品导航中

Just installed Wordpress with BeTheme and Woocommerce in it and faced the following problem: when enter single product page there is Next-Prev buttons showing some info about next-prev product - name, date of upload, picture. Now I want to add price also but nothing found in StackOverflow works for me.

Here is my code, want to add the price instead of the date.

If need can provide the code of theme-shortcodes.php file.

Thank you in advance.

    if( is_object( $post ) ){
        // move this DOM element with JS
        $output .= '<a class="fixed-nav fixed-nav-'. $next_prev .' format-'. get_post_format( $post ) .'" href="'. get_permalink( $post ) .'">';

            $output .= '<span class="arrow"><i class="'. $icon .'"></i></span>';

            $output .= '<div class="photo">';
                $output .= get_the_post_thumbnail( $post->ID, 'blog-navi' );
            $output .= '</div>';

            $output .= '<div class="desc">';
                $output .= '<h6>'. get_the_title( $post ) .'</h6>';
                $output .= '<span class="date"><i class="icon-clock"></i>'. get_the_date(get_option('date_format'), $post->ID) .'</span>';
            $output .= '</div>';

        $output .= '</a>';
    }
  • 写回答

2条回答 默认 最新

  • douan4106 2019-03-27 12:50
    关注

    You can create a product object using the following function:

    $product = wc_get_product( $post->ID );
    

    And after that you will be able to access to all product's data. All available methods can be found here, but the ones you need are:

    $regular_price = $product->get_regular_price();
    $sale_price = $product->get_sale_price();
    $price = $product->get_price();
    

    and echo the price variable which price do you want to show.

    评论

报告相同问题?

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)