Home Forums WoodMart support forum Side Menu Suggestion

Side Menu Suggestion

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #381700

    iamfahrig
    Participant

    Side Menu Suggestion

    Side Menu

    • This topic was modified 2 years, 7 months ago by iamfahrig.
    Attachments:
    You must be logged in to view attached files.
    #381714

    Luke Nielsen
    Keymaster

    Hello,

    Thanks for reaching us, we really appreciate your feedback! We are always trying to improve our product to provide you with a better experience. I will be sure to pass your suggestion onto our team for their consideration.

    If you have any questions or wish to learn more about our theme, do reach out to our customer service team at any time

    Kind Regards

    #388157

    iamfahrig
    Participant

    Add the following Custom CSS to the Public Custom CSS field under Theme Settings >> Custom CSS.
    ———————————————————————————————-

    //Kupon Kodu Otomatik Açılır Hale Getirme Kodu//
    .woocommerce-checkout .checkout_coupon.woocommerce-form-coupon {
        display: block !important;
    }

    ———————————————————————————————-
    In the functions.php, add the following code:
    ———————————————————————————————-

    // Remove default coupon field
    remove_action( 'woocommerce_before_checkout_form', 'woocommerce_checkout_coupon_form', 10 );
    
    // Add a custom coupon field before checkout payment section
    add_action( 'woocommerce_review_order_before_payment', 'woocommerce_checkout_coupon_form_custom' );
    function woocommerce_checkout_coupon_form_custom() {
        echo '<div class="coupon-form" style="margin-bottom:20px;">
            <p>' . __("İNDİRİM KODU GİR") . '</p>
            <p class="form-row form-row-first woocommerce-validated">
                <input type="text" name="coupon_code" class="input-text" placeholder="' . __("Kodunuzu Giriniz") . '" id="coupon_code" value="">
            </p>
            <p class="form-row form-row-last">
                <button type="button" class="button" name="apply_coupon" value="' . __("Apply coupon") . '">' . __("UYGULA") . '</button>
            </p>
            <div class="clear"></div>
        </div>';
    }
    
    // jQuery - Send Ajax request
    add_action( 'wp_footer', 'custom_checkout_jquery_script' );
    function custom_checkout_jquery_script() {
        if ( is_checkout() && ! is_wc_endpoint_url() ) :
        ?>
        <script type="text/javascript">
        jQuery( function($){
            if (typeof wc_checkout_params === 'undefined')
                return false;
    
            var couponCode = '';
    
            $('input[name="coupon_code"]').on( 'input change', function(){
                couponCode = $(this).val();
            });
    
            $('button[name="apply_coupon"]').on( 'click', function(){
                $.ajax({
                    type: 'POST',
                    url: wc_checkout_params.ajax_url,
                    data: {
                        'action': 'apply_checkout_coupon',
                        'coupon_code': couponCode,
                    },
                    success: function (response) {
                        $(document.body).trigger("update_checkout"); // Refresh checkout
                        $('.woocommerce-error,.woocommerce-message').remove(); // Remove other notices
                        $('input[name="coupon_code"]').val(''); // Empty coupon code input field
                        $('form.checkout').before(response); // Display notices
                        // console.log(response); // Uncomment for testing
                    }
                });
            });
        });
        </script>
        <?php
        endif;
    }
    
    // Ajax receiver function
    add_action( 'wp_ajax_apply_checkout_coupon', 'apply_checkout_coupon_ajax_receiver' );
    add_action( 'wp_ajax_nopriv_apply_checkout_coupon', 'apply_checkout_coupon_ajax_receiver' );
    function apply_checkout_coupon_ajax_receiver() {
        if ( isset($_POST['coupon_code']) && ! empty($_POST['coupon_code']) ) {
            WC()->cart->add_discount( wc_format_coupon_code( wp_unslash( $_POST['coupon_code'] ) ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
        } else {
            wc_add_notice( WC_Coupon::get_generic_coupon_error( WC_Coupon::E_WC_COUPON_PLEASE_ENTER ), 'error' );
        }
        wc_print_notices();
        wp_die();
    }
    Attachments:
    You must be logged in to view attached files.
    #388360

    Luke Nielsen
    Keymaster

    Hello,

    Please, describe the above code, is that your problem or suggestion?

    Looking forward to hearing back from you!

    Kind Regards

    #388451

    iamfahrig
    Participant

    Suggestion Move coupon form before payment section in WooCommerce checkout
    Move coupon form before payment section in WooCommerce checkout
    ———————————————————————————————-
    In the functions.php, add the following code:
    ———————————————————————————————-

    // Just hide default woocommerce coupon field
    add_action( 'woocommerce_before_checkout_form', 'hide_checkout_coupon_form', 5 );
    function hide_checkout_coupon_form() {
        echo '<style>.woocommerce-form-coupon-toggle {display:none;}</style>';
    }
    
    // Add a custom coupon field before checkout payment section
    add_action( 'woocommerce_review_order_before_payment', 'woocommerce_checkout_coupon_form_custom' );
    function woocommerce_checkout_coupon_form_custom() {
        echo '<div class="checkout-coupon-toggle"><div class="woocommerce-info">' . sprintf(
            __("Have a coupon? %s"), '<a href="#">' . __("Click here to enter your code") . '</a>'
        ) . '</div></div>';
    
        echo '<div class="coupon-form" style="margin-bottom:20px;" style="display:none !important;">
            <p>' . __("If you have a coupon code, please apply it below.") . '</p>
            <p class="form-row form-row-first woocommerce-validated">
                <input type="text" name="coupon_code" class="input-text" placeholder="' . __("Coupon code") . '" id="coupon_code" value="">
            </p>
            <p class="form-row form-row-last">
                <button type="button" class="button" name="apply_coupon" value="' . __("Apply coupon") . '">' . __("Apply coupon") . '</button>
            </p>
            <div class="clear"></div>
        </div>';
    }
    
    // jQuery code
    add_action( 'wp_footer', 'custom_checkout_jquery_script' );
    function custom_checkout_jquery_script() {
        if ( is_checkout() && ! is_wc_endpoint_url() ) :
        ?>
        <script type="text/javascript">
        jQuery( function($){
            $('.coupon-form').css("display", "none"); // Be sure coupon field is hidden
            
            // Show or Hide coupon field
            $('.checkout-coupon-toggle .show-coupon').on( 'click', function(e){
                $('.coupon-form').toggle(200);
                e.preventDefault();
            })
            
            // Copy the inputed coupon code to WooCommerce hidden default coupon field
            $('.coupon-form input[name="coupon_code"]').on( 'input change', function(){
                $('form.checkout_coupon input[name="coupon_code"]').val($(this).val());
                // console.log($(this).val()); // Uncomment for testing
            });
            
            // On button click, submit WooCommerce hidden default coupon form
            $('.coupon-form button[name="apply_coupon"]').on( 'click', function(){
                $('form.checkout_coupon').submit();
                // console.log('click: submit form'); // Uncomment for testing
            });
        });
        </script>
        <?php
        endif;
    }
    • This reply was modified 2 years, 6 months ago by iamfahrig.
    #388517

    Luke Nielsen
    Keymaster

    Hello,

    Thank you for your suggestions, if you have more ideas, please describe them in this https://xtemos.com/forums/topic/features-requests-2/ topic, it’s a special topic for the customer’s suggestions.

    Have a good day!

    Kind Regards

    #392929

    iamfahrig
    Participant

    You can close the topic.

    #392935

    Luke Nielsen
    Keymaster

    Hello,

    Don’t hesitate to reach out if you have any more questions or concerns. We’re thankful that you took the time to share your concerns with us.

    Wish you all the best.

    Kind Regards

Viewing 8 posts - 1 through 8 (of 8 total)

The topic ‘Side Menu Suggestion’ is closed to new replies.