duanche4578 2018-12-12 03:59
浏览 26

获取Woocommerce产品定制主题

I'm trying to get woocommerce products on owl-carousel slider, im able to get product thumbnail, title, price and add to cart button but as in shop page when we click on add-to-cart button we get view-cart-button (add-to-cart button does behave as ajax button) by side which im unable to get in my code, I was able get whole session of product from below code:

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

but this doesn't give me full freedom to play with code. but this code give view-cart button too.

Below is the code I have done so far

<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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
    • ¥20 软件测试决策法疑问求解答
    • ¥15 win11 23H2删除推荐的项目,支持注册表等
    • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
    • ¥15 qt6.6.3 基于百度云的语音识别 不会改
    • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
    • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
    • ¥15 lingo18勾选global solver求解使用的算法
    • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
    • ¥20 测距传感器数据手册i2c