Z
Z
zorgankal2017-08-14 09:38:30
WordPress
zorgankal, 2017-08-14 09:38:30

How to display the price of a product and add a button to the cart in the search results?

Help with advice, in general, there is a site topshop.dp.ua picking the woo manuals and the Customizr theme manual. From everything else I came across serch-form.php and wrote this

<?php
/**
 * The template for displaying the full page search form
 */
?>
<section class="overlay search_o">
  <a href="#" class="search-close_btn"><i class="icn-close"></i></a>
  <div class="overlay-content">
    <div class="search__wrapper">
    <?php get_search_form() ?>
    </div>
  </div>
</section>
<?php get_header() ?>
<div id="content">
    <div id="center">
        <h1><?php echo 'Результат поиска: ' . '<span>' . get_search_query() . '</span>'; ?></h1>
        <?php
        if (have_posts()) :
            while (have_posts()) : the_post();
                ?>
                <div id="posts">
                    <h2><a href="<?php the_permalink() ?>"><?php the_title() ?></a></h2>
                     <h2><span class="price">Цена: <?php echo $product->get_price_html(); ?></span> </h2>
                     <h2> <span class="woocommerce-Price-currencySymbol">грн.</span></h2>
                    <div id="post_info">
                        <div>Дата добавления: <?php the_date() ?></div>
                        <div id="clear"></div>
                    </div>
                    <p><?php the_excerpt() ?></p>
                    <span>Категория: <?php the_category(', ') ?></span>
                </div>
            <?php endwhile; ?>
        <?php
        else :
            echo "Извините по Вашему результату ничего не найдено";
        endif;
        ?>
    </div>
    <?php get_sidebar() ?>
<?php get_footer() ?>

The result of starting the page = (... I have the advance woocommerce search plugin (for live search) enabled and the theme function says that the search returns the product category for the word that the user specified in the search form.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
obemgcabazn, 2017-08-16
@obemgcabazn

You can add a button in a loop like this:
echo sprintf( '<a href="%s" data-quantity="1" data-product_id="%s" data-product_sku="%s" class="add-to- cart">Add to Cart</a>',
esc_url( $product->add_to_cart_url() ),
esc_attr( $product->id ),
esc_attr( $product->get_sku() )
)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question