dousi2553 2016-06-05 22:13 采纳率: 0%
浏览 37

WooCommerce:按钮进入Pay​​U结账页面

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)

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 西门子S7-Graph,S7-300,梯形图
    • ¥50 用易语言http 访问不了网页
    • ¥50 safari浏览器fetch提交数据后数据丢失问题
    • ¥15 matlab不知道怎么改,求解答!!
    • ¥15 永磁直线电机的电流环pi调不出来
    • ¥15 用stata实现聚类的代码
    • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
    • ¥20 docker里部署springboot项目,访问不到扬声器
    • ¥15 netty整合springboot之后自动重连失效
    • ¥15 悬赏!微信开发者工具报错,求帮改