在woocommerce购物车页面上显示优惠券表格

时间:2015-11-03 17:56:44

标签: wordpress woocommerce

如何在购物车页面中使用优惠券表格form-coupon.php?此表单通常附在结帐页面上,但确实希望将其放在购物车页面中。

2 个答案:

答案 0 :(得分:0)

add_action( 'woocommerce_before_cart', 'woocommerce_checkout_coupon_form', 10 );

您可能需要更改js才能触发下拉列表

答案 1 :(得分:0)

这对你有帮助!!

       add_action('woocommerce_cart_coupon', 'woocommerce_cart_coupon_list');
        function woocommerce_cart_coupon_list() {
            $args = array(
                'posts_per_page'   => 500,
                'orderby'          => 'title',
                'order'            => 'desc',
                'post_type'        => 'shop_coupon',
                'post_status'      => 'publish',
                  'orderby'   => 'meta_value',
                'order' => 'DESC',
            );
            
            $coupons = get_posts( $args );
        
            $coupon_names = array();
            foreach ( $coupons as $coupon ) {
                // Get the name for each coupon post
                $coupon_name = $coupon->post_title;
                array_push( $coupon_names, $coupon_name );
            }
            ?>
                <div style="height:200px; overflow-y:scroll;" >
                    <h4>
                    Get Dicount by Choosing coupon code: </br>  
                    </h4>
        
                 <?php
                    foreach ($coupon_names as $key => $value) {
                //      echo "<span><p> " . $value . " </p></span>\r\n"; 
                        
                        global $woocommerce;
                        $c = new WC_Coupon($value);
                        
                        ?>
        
                        <details>
                            <summary style="color:#aa6860; font-size:16px; font-weight: bold; padding-bottom: 2%;
            padding-top: 2%;"> <?=$c->get_description(); ?></summary>
        <!--                    <p> Amount :- <?= $c->amount; ?> </p> -->
                            <?php
                                echo "<p class='coupon-description'>Coupon Code :- " . $value ."</p>";
                            ?>
                            
                        </details>
                        
                        
                <?php   }
                 ?>
                </div>
            <?php`enter code here`
               
        }