Answers for "woocommerce woocommerce_loop_add_to_cart_link"

C
0

woocommerce loop through product categories

<ul class="products">
    <?php
    $args = array(
        'product_cat' => 'Shampoo',
        'posts_per_page' => 4,
        'orderby' => 'rand'
    );
    $loop = new WP_Query($args);
    while ($loop->have_posts()) : $loop->the_post();
        global $product; ?>
        <div class="row">
            <!-- <h2>Shampoo</h2> -->
            <li class="product">

                <a href="<?php echo get_permalink($loop->post->ID) ?>" title="<?php echo esc_attr($loop->post->post_title ? $loop->post->post_title : $loop->post->ID); ?>">

                    <?php woocommerce_show_product_sale_flash($post, $product); ?>

                    <?php if (has_post_thumbnail($loop->post->ID)) echo get_the_post_thumbnail($loop->post->ID, 'shop_catalog');
                    else echo '<img src="' . woocommerce_placeholder_img_src() . '" alt="Placeholder" width="300px" height="300px" />'; ?>

                    <h3><?php the_title(); ?></h3>

                    <span class="price"><?php echo $product->get_price_html(); ?></span>

                </a>

                <?php woocommerce_template_loop_add_to_cart($loop->post, $product); ?>
            </li>
        </div>
    <?php endwhile; ?>
    <?php wp_reset_query(); ?>
</ul>
<!--/.products-->
Posted by: Guest on September-13-2021
0

add_to_cart how to call it woocommerce

add_action( 'template_redirect', 'quadlayers_add_to_cart_function' );

function quadlayers_add_to_cart_function () {

    $product_id = 1326;

    if ( WC()->cart->get_cart_contents_count() == 0 ) {

        WC()->cart->add_to_cart( $product_id );

    }

}
Posted by: Guest on December-08-2020

Code answers related to "C"

Browse Popular Code Answers by Language