我正在开发销售虚拟产品的 WooCommerce 商店网站。我制作了一个自定义结帐页面,客户可以在其中放置所有结帐数据,最后可以在 2 个选项之间进行选择:
- 选项 1 -稍后付款:仅向客户和管理员发送邮件。
- 选项 2 -立即付款:需要使用PayU支付网关。
现在,问题来了:
由于文档很差,我找不到将我带到适当结帐页面的代码。
我尝试使用继续结帐功能,但它会将我返回到我单击它的同一网站。
回声wc_get_checkout_url()
不返回任何内容。
我什至尝试使用 payment.php 中的一些代码,结果如下:
<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>
但就像之前的尝试一样,它根本没有用。
网站使用点击时触发的自定义预订 ajax 功能:
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
有什么正确的方法可以完成这项工作吗?
这是整个自定义结帐页面的代码:
<?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(); ?>
PayU插件已经设置和配置。
该网站可以在这里找到(波兰语)