0

I'm working on a WooCommerce store website selling virtual products. I've made a custom checkout page where customer would put all his checkout data and at the end could chose between 2 options:

  • Option 1 - Paying later: Only sends a mail to customer and to admin.
  • Option 2 - Paying now: Requires using PayU payment gateway.

Now, here is the problem:
Due to very poor documentation I cant find the code that would take me to the appropriate checkout page.
I tried using the proceed to checkout function but it returns me to the same website I clicked it from.

Echoing wc_get_checkout_url() returns nothing.

I even tried using some of the code from payments.php, resulting in this:

<div class="col-md-12 text-center col-form">
    <?php
    if ( ! is_ajax() ) {
        do_action( 'woocommerce_review_order_before_payment' );
    }
    if ( WC()->cart->needs_payment() ) : ?>
        <ul class="wc_payment_methods payment_methods methods">
        <?php
            echo "ekhm". esc_url( wc_get_checkout_url()) //testing;
            if ( ! empty( $available_gateways ) ) {
                foreach ( $available_gateways as $gateway ) {
                    wc_get_template( 'checkout/payment-method.php', array( 'gateway' => $gateway ) );
                }
            }; ?>
        </ul>
    <?php endif; ?>


    <!-- <button class="submit-reservation materialbutton">Payment and reserwavion</button>
    <button id="reservation-button" class="submit-reservation materialbutton" id="just-reserve">Just Reserve</button> -->
</div>

But alike previous attempts, it didn't work at all.

Website uses a custom booking ajax function firing on click:

function addToCart(p_id) {
        var getAjax =  $.get('../?post_type=product&add-to-cart=' + p_id, function(){updateCart(1); notify("Added!");});
} //updateCart is for display only

Is there any correct way I can make this work?

Here is the code for the entire custom checkout page:

<?php
/* Template Name: reservation*/
get_header();
sm_small_slider(get_the_title());?>
<script type="text/javascript">
var templateUrl = '<?= get_bloginfo("template_url"); ?>';
</script>
</header>
<section id="reservation">
<div class="container">
    <ul class="resevation-order-list">
        <div class='row product-list'> <!-- first step: the cart -->
        <div class="col-md-3 text-right col-description">
            <h4>1) Twoje Zabiegi</h4>
            <p>Przed wyborem terminu, upewnij się czy wszystko się zgadza</p>
        </div>
        <div class="col-md-9 text-left col-form form-cart">
            <div class="form-content">
                <?php
                //THE CART IS PRINTED HERE
                global $woocommerce;
                if($items = $woocommerce->cart->get_cart()){
                ?>
                <table class="treatments-table table">
                    <tr class="table-heading">
                        <th>Usługa</th>
                        <th>Czas trwania</th>
                        <th>Cena</th>
                        <th></th>
                    </tr>
                    <?php
                    foreach($items as $item => $values) {
                    $_product = $values['data']->post;
                    $price = get_post_meta($values['product_id'] , '_price', true);
                    ?>
                    <tr>
                        <td class="name mail-cc"><?php echo $_product->post_title; ?> - <?php echo $values['quantity']; ?></td>
                        <td class="mail-cc"><?php echo $_product->post_excerpt;?></td>
                        <td class="mail-cc"><?php echo $price * $values['quantity']; ?>zł</td>
                        <td><img title="usuń z listy" onClick="removeFromCart(<?php echo $values['product_id'];?>)" src="<?php echo get_template_directory_uri();?>/img/navigation/close.png" /><a class="remove-from" href="javascript:removeFromCart(<?php echo $values['product_id'];?>)">USUŃ Z LISTY</p></td>
                    </tr>
                    <?php } ?>
                    <tr>
                        <td class="name"><b>Suma</b></td>
                        <td></td>
                        <td><?php echo WC()->cart->get_cart_total(); ?></td>
                        <td></td>
                    </tr>
                </table>
                <?php }else{
                echo "<p style='opacity: 0.5'>KOSZYK JEST PUSTY </p>";}?>
            </div>
        </div>
    </div>
    <div class="row pick-date">
        <div class="col-md-3 text-right col-description">
            <!-- here the customer picks the date and day-time of his reservation -->
            <h4>2) Wybierz Termin</h4>
            <p>Wybierz w kalendarzu dzień, oraz porę dnia Twojej Rezerwacji</p>
        </div>
        <div class="col-md-9 text-left col-form">
            <div id="calendar">
                <div class="calendar-container clearfix">
                </div>
            </div>
            <div class="calendar-nav-left">
                <img src="<?php echo get_template_directory_uri();?>/img/navigation/arrow_l.png" class="calendar-arrow" />
            </div>
            <div class="calendar-nav-right">
                <img src="<?php echo get_template_directory_uri();?>/img/navigation/arrow.png" class="calendar-arrow" />
            </div>
        </div>
    </div>
    <div class="row personal-data-form">
        <div class="col-md-3 text-right col-description">
            <!-- CONTACT FORM  -->
            <h4>3) Dane Osobowe</h4>
            <p>Prosimy o podanie swoich dokładnych danych osobowych</p>
            <p>Wszystkie pola są wymagane</p>
        </div>
        <div class="col-md-9 text-left col-form">
            <form id="reservation-form" class="contact-form">
                <input type="hidden" id="adminname" value="<?php echo get_bloginfo('admin_email'); ?>"/>
                <input required id="firstname" type="text" placeholder="Imię"></input>
                <input required id="lastname"type="text" placeholder="Nazwisko"></input>
                <input required type="email" placeholder="Email" id="email"></input>
                <input required type="text" id="phonenum" placeholder="Numer telefonu"></input>
                <input required type="text" id="city" placeholder="Miejscowość"></input>
                <input required type="text" id="street" placeholder="Ulica"></input>
                <input required type="text" id="address" placeholder="Numer domu/Mieszkania"></input>
                <input required type="checkbox" name="accept" value="Accept" id="akceptuje-regulamin"> Akceptuje <a href="http://mobilnestudio16.pl/regulamin/" class="purple">regulamin</a><br>
            </form>
            <p>Działamy na terenie Krakowa i okolic</p>
        </div>
    </div>
    <div class="row submit-and-pay">
        <div class="col-md-12 text-center col-description">
            <h4>Płatność i Rezerwacja</h4>
            <p>Kliknij przycisk by zaakceptować dane i przejść do strony płatności</p>
            <!-- <p>Płatność z PayU</p> -->
        </div>

        <div class="col-md-12 text-center col-form">
            <?php
            if ( ! is_ajax() ) {
    do_action( 'woocommerce_review_order_before_payment' );
}
             if ( WC()->cart->needs_payment() ) : ?>
                                <ul class="wc_payment_methods payment_methods methods">
                                    <?php
                                    echo esc_url( wc_get_checkout_url() );
                                        if ( ! empty( $available_gateways ) ) {
                                            foreach ( $available_gateways as $gateway ) {
                                                wc_get_template( 'checkout/payment-method.php', array( 'gateway' => $gateway ) );
                                            }
                                        }; ?>
                                </ul>
                            <?php endif;?>

            <!-- This button has been commented out due to website being live -->
            <!-- But its the button I would like to make the page go to PayU checkout for payments-->
            <!-- <button class="submit-reservation materialbutton">Płacę i rezerwuję</button> -->
            <button id="reservation-button" class="submit-reservation materialbutton" id="just-reserve">Rezerwuję</button>
        </div>
    </div>
</ul><!--!RESERVATION ORDER LIST-->
</div>
</section>

<script type="text/javascript" src="<?php bloginfo("template_url"); ?>/scripts/calendar.js"></script>
<?php get_footer(); ?>

The PayU plugin has already been set up and configured.

The website can be found HERE(Polish)

aln447
  • 981
  • 2
  • 15
  • 44
  • Normally when you add product to cart, you go afterward to checkout page then you choose the payment method for this order. For each enabled payment gateway plugins, you will have in that checkout page, a checkbox that you can select before submitting the order. When you submit the order with a selected payment gateway, you are taken to this payment gateway. If payU is enabled in checkout settings, why do you want to add a button? Your question is unclear. Please could you be more explicit and provide a link to your website (or some screenshots) updating your question. Thanks. – LoicTheAztec Jun 06 '16 at 03:31
  • The question has been edited, look at the bottom line pleease – aln447 Jun 06 '16 at 03:34
  • Sorry but you have omitted to add that you are using some additional plugin for booking… Could you update your question with those details. Some commented screenshots could be very helpful to find out the right solution. – LoicTheAztec Jun 06 '16 at 03:41
  • Oh, I'm sorry. please check now – aln447 Jun 06 '16 at 03:59
  • What plugin are you using for booking purpose? This booking plugin is changing normal woocommerce checkout behavior. Have you override checkout templates with some custom code? Your question is not clear as it is know. – LoicTheAztec Jun 06 '16 at 07:50
  • The checkout template was build from scratch because I din't know woocommerce that good at the time. So I build a normal wp template and then installed woocommerce onto it. I will now publish the script of the complete page, with comments for you – aln447 Jun 06 '16 at 10:36
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/113906/discussion-between-aln447-and-loictheaztec). – aln447 Jun 06 '16 at 10:39

0 Answers0