dongzheng7165 2019-08-09 03:28
浏览 89

如何在WooCommerce中构建基本产品简介?

I'm really new into WooCommerce and not an expert in WooCommerce, I have developed custom WordPress themes but not WooCommerce.

I have been trying to use different codes to display certain things like Attributes, Add to cart button, title, etc. I have managed to do almost everything, I had the Add to Cart button but I need to have sizes in a dropdown (i already have the attributes created) so my button just converted itself into "Select Options" when I made this product "Variable". So now I'm pretty confused

<h1>
  <?php echo $product->get_title(); ?>
</h1>
<div class="amount">$
  <?php echo $product->get_price ()?>
</div>    
<p class="product-description">
  <?php echo $product->get_description(); ?>
</p>
<!-- Add to Cart Button -->
<?php  
global $product;
echo apply_filters( 'woocommerce_loop_add_to_cart_link',
sprintf( '<a href="%s" rel="nofollow" data-product_id="%s" data-product_sku="%s" class="button %s product_type_%s">%s</a>',
esc_url( $product->add_to_cart_url() ),
esc_attr( $product->id ),
esc_attr( $product->get_sku() ),
$product->is_purchasable() ? 'add_to_cart_button' : '',
esc_attr( $product->product_type ),
esc_html( $product->add_to_cart_text() )
),
$product );
?>
<?php
$subheadingvalues = get_terms('size', array(
'hide_empty' => false,
));
?> 
<select>
  <?php foreach ($subheadingvalues as $subheadingvalue): ?>
  <option value="<?php echo $subheadingvalue->name; ?>">
    <?php echo $subheadingvalue->name; ?>
  </option>
  <?php endforeach;?>
</select>

This is how it looks now: http://prntscr.com/oqbyry This is what I'm trying to achieve: http://prntscr.com/oqbzb6

Any help would be greatly appreciated! Sorry if this is not well formatted, it's my first post.

  • 写回答

1条回答 默认 最新

  • doupinwan0563 2019-08-09 05:48
    关注

    I corrected your code. Can you please check and let me know if it's working.

    <h1><?php echo $product->get_title(); ?></h1>
                      <div class="amount">$<?php echo $product->get_price ()?></div>    
                      <p class="product-description"><?php echo $product->get_description(); ?></p>
    
                      <!-- Add to Cart Button -->
                      <?php  
                        global $product;
    
                        echo apply_filters( 'woocommerce_loop_add_to_cart_link',
                            sprintf( '<a href="%s" rel="nofollow" data-product_id="%s" data-product_sku="%s" class="button %s product_type_%s">%s</a>',
                                esc_url( $product->add_to_cart_url() ),
                                esc_attr( $product->id ),
                                esc_attr( $product->get_sku() ),
                                $product->is_purchasable() ? 'add_to_cart_button' : '',
                                esc_attr( $product->product_type ),
                                esc_html( $product->add_to_cart_text() )
                            ),
                        $product );
                      ?>
            <?php 
            global $product;
            $handle=new WC_Product_Variable($product->get_id());
                    $variations1=$handle->get_children();
                    echo '<select>';
                    foreach ($variations1 as $value) {
                    $single_variation=new WC_Product_Variation($value);
                        echo '<option  value="'.$value.'">'.implode(" / ", $single_variation->get_variation_attributes()).'-'.get_woocommerce_currency_symbol().$single_variation->price.'</option>';
            }
            echo '</select>';
                ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)