• Resolved javierpernettr

    (@javierpernettr)


    I need to show the product price with your plugin, im using woocomerce, i already used your plugin in another website and its great, but i dont know how to show the price, can you explain me how to achieve that?, i need to show after the title and before the button or link of “read more”

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author thehowarde

    (@thehowarde)

    Hi @javierpernettr

    To add the price to a Product Carousel… You need to add something like this snippet of code to your functions.php in your theme/child theme.

    <?php
        function add_wc_price_to_carousel(){
        global $post, $woocommerce;
        $product = wc_get_product( $post->ID );
        if ($product) {
            echo '<p class="price">$' . $product->get_price() . '</p>' ;
            echo '<a href="'.get_permalink( $post->ID ).'" class="btn btn-primary ">Shop Now</a>';
            }
        }
        add_action('dd-carousel-after-content', 'add_wc_price_to_carousel', 10);
    

    This would add both a price and a shop now button…

    Thread Starter javierpernettr

    (@javierpernettr)

    Thanks a lot, your plugin is great, i will give you five stars, there is a way to show also the stars of the reviews for the current product and the excerpt? im searching the right codex or sintax but im a little newbie in this.

    Plugin Author thehowarde

    (@thehowarde)

    Hi. @javierpernettr

    This will show the star rating – only if the average rating is greater than 0 and on a specific carousel. Change the ID to that of your carousel.

    function add_wc_price_to_carousel($carousel_id) {
        global $post, $woocommerce;
        // Check my Carousel ID is the one I want
        if ($carousel_id !== '2282') return;
        $product = wc_get_product($post->ID);
        if ($product) {
            $average = $product->get_average_rating();
            echo '<p class="price">$' . $product->get_price() . '</p>';
            echo '<a href="' . get_permalink($post->ID) . '" class="btn btn-primary ">Shop Now</a>';
            if ($average > 0) {
                echo '<div class="woocommerce"><div class="star-rating"><span style="width:' . (($average / 5) * 100) . '%"><strong itemprop="ratingValue" class="rating">' . $average . '</strong> ' . __('out of 5', 'woocommerce') . '</span></div></div>';
            }
        }
    }
    
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Show the product price’ is closed to new replies.