show coupon form on the woocommerce cart page

How can I use the coupon form form-coupon.php in my cart page? This form is normally attached to the checkout page but really want to have it in the shopping cart page instead.

Related posts

2 comments

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

    You will probably need to alter the js to trigger the dropdown

  2. This will help you !!

           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>rn"; 
                            
                            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`
                   
            }
    

Comments are closed.