在定制主题上获取Woocommerce产品

时间:2018-12-12 03:59:27

标签: php wordpress woocommerce

我正在尝试在猫头鹰轮播滑块上获取woocommerce产品,无法获取产品缩略图,标题,价格并添加到购物车按钮,但是就像在商店页面中,当我们单击添加到购物车按钮时,我们可以查看-cart-button(添加到购物车中的按钮的行为确实像ajax按钮一样),即时通讯无法进入我的代码,我可以从以下代码中获得整个产品会话:

<?php woocommerce_get_template_part( 'content', 'product' ); ?>

但是,这并没有给我充分的自由来玩代码。但是此代码也提供了查看购物车按钮。

下面是我到目前为止完成的代码

<div class="container">
    <div class="row">
        <div id="owl-example" class="owl-carousel owl-one">
<?php 
    $args = array(
        'post_type'      => 'product',
        'posts_per_page' => 10

    );

    $loop = new WP_Query( $args );

    while ( $loop->have_posts() ) : $loop->the_post();
        global $product;
?>
            <div class="item">
        <a href="<?php echo get_permalink(); ?>">

            <p><?php the_post_thumbnail(); ?></p>
            <p><?php echo get_the_title(); ?></p>

            <p><?php echo wc_price($product->get_price()); ?></p>
            <p>
                <?php if($product->has_child()) : ?>
<a href="<?php the_permalink(); ?>">
<?php _e('Zobacz dostępne warianty', 'my-theme'); ?>
</a>
<?php elseif($product->is_in_stock()) : ?>
<form class="cart" action="<?php the_permalink() ?>" method="post" enctype="multipart/form-data">
     <div class="quantity">
          <input type="number" step="1" min="1" max="9" name="quantity" value="1" title="<?php _e('Szt.', 'my-theme'); ?>" class="input-text qty text" size="4">
     </div>
     <input type="hidden" name="add-to-cart" value="<?php echo esc_attr($product->id); ?>">
     <button type="submit"><?php echo $product->single_add_to_cart_text(); ?></button>
</form>
<?php endif; ?>
            </p>
                <p><a class="button custom-button" href=<?php echo esc_attr( $product->get_permalink() ); ?> ></p>
        </a>
                </div>
<?php
    endwhile;

    wp_reset_query();
?>
        </div>
    </div>
</div>

0 个答案:

没有答案