woocommerce/shortcodes/shortcode-pay.php

128 lines
3.5 KiB
PHP
Raw Normal View History

2011-08-10 17:11:11 +00:00
<?php
/**
* Pay Shortcode
2012-08-14 17:37:50 +00:00
*
2011-11-28 18:49:32 +00:00
* The pay page. Used for form based gateways to show payment forms and order info.
2011-08-10 17:11:11 +00:00
*
2012-08-14 17:37:50 +00:00
* @author WooThemes
* @category Shortcodes
* @package WooCommerce/Shortcodes/Pay
* @version 1.6.4
*/
/**
* Get the pay shortcode content.
*
* @access public
* @param array $atts
* @return string
2011-08-10 17:11:11 +00:00
*/
function get_woocommerce_pay( $atts ) {
global $woocommerce;
2012-08-14 17:37:50 +00:00
return $woocommerce->shortcode_wrapper('woocommerce_pay', $atts);
2011-08-10 17:11:11 +00:00
}
2012-08-14 17:37:50 +00:00
2011-08-10 17:11:11 +00:00
/**
* Outputs the pay page - payment gateways can hook in here to show payment forms etc
2012-08-14 17:37:50 +00:00
*
* @access public
* @return void
*/
2011-08-10 17:11:11 +00:00
function woocommerce_pay() {
2012-02-03 16:17:35 +00:00
global $woocommerce;
2012-08-14 17:37:50 +00:00
2012-02-24 21:05:15 +00:00
$woocommerce->nocache();
2012-08-14 17:37:50 +00:00
2012-02-08 17:45:01 +00:00
do_action('before_woocommerce_pay');
2012-08-14 17:37:50 +00:00
2012-02-09 13:58:34 +00:00
$woocommerce->show_messages();
2012-08-14 17:37:50 +00:00
2011-08-10 17:11:11 +00:00
if ( isset($_GET['pay_for_order']) && isset($_GET['order']) && isset($_GET['order_id']) ) :
2012-08-14 17:37:50 +00:00
2011-08-10 17:11:11 +00:00
// Pay for existing order
$order_key = urldecode( $_GET['order'] );
$order_id = (int) $_GET['order_id'];
2012-01-27 16:38:39 +00:00
$order = new WC_Order( $order_id );
2012-08-14 17:37:50 +00:00
if ($order->id == $order_id && $order->order_key == $order_key && in_array($order->status, array('pending', 'failed'))) :
2012-08-14 17:37:50 +00:00
2011-08-10 17:11:11 +00:00
// Set customer location to order location
if ($order->billing_country) $woocommerce->customer->set_country( $order->billing_country );
if ($order->billing_state) $woocommerce->customer->set_state( $order->billing_state );
if ($order->billing_postcode) $woocommerce->customer->set_postcode( $order->billing_postcode );
2012-08-14 17:37:50 +00:00
2011-08-10 17:11:11 +00:00
// Show form
2012-02-03 16:17:35 +00:00
woocommerce_get_template('checkout/form-pay.php', array('order' => $order));
2012-08-14 17:37:50 +00:00
elseif (!in_array($order->status, array('pending', 'failed'))) :
2012-08-14 17:37:50 +00:00
2012-10-16 09:45:33 +00:00
$woocommerce->add_error( __( 'Your order has already been paid for. Please contact us if you need assistance.', 'woocommerce' ) );
$woocommerce->show_messages();
2012-08-14 17:37:50 +00:00
2011-08-10 17:11:11 +00:00
else :
2012-08-14 17:37:50 +00:00
2012-10-16 09:45:33 +00:00
$woocommerce->add_error( __( 'Invalid order.', 'woocommerce' ) );
$woocommerce->show_messages();
2012-08-14 17:37:50 +00:00
2011-08-10 17:11:11 +00:00
endif;
2012-08-14 17:37:50 +00:00
2011-08-10 17:11:11 +00:00
else :
2012-08-14 17:37:50 +00:00
2011-08-10 17:11:11 +00:00
// Pay for order after checkout step
if (isset($_GET['order'])) $order_id = $_GET['order']; else $order_id = 0;
if (isset($_GET['key'])) $order_key = $_GET['key']; else $order_key = '';
2012-08-14 17:37:50 +00:00
2011-08-10 17:11:11 +00:00
if ($order_id > 0) :
2012-08-14 17:37:50 +00:00
2012-01-27 16:38:39 +00:00
$order = new WC_Order( $order_id );
2012-08-14 17:37:50 +00:00
if ($order->order_key == $order_key && in_array($order->status, array('pending', 'failed'))) :
2012-08-14 17:37:50 +00:00
2011-08-10 17:11:11 +00:00
?>
<ul class="order_details">
<li class="order">
2012-10-16 09:45:33 +00:00
<?php _e( 'Order:', 'woocommerce' ); ?>
<strong><?php echo $order->get_order_number(); ?></strong>
2011-08-10 17:11:11 +00:00
</li>
<li class="date">
2012-10-16 09:45:33 +00:00
<?php _e( 'Date:', 'woocommerce' ); ?>
2012-01-25 15:23:32 +00:00
<strong><?php echo date_i18n(get_option('date_format'), strtotime($order->order_date)); ?></strong>
2011-08-10 17:11:11 +00:00
</li>
<li class="total">
2012-10-16 09:45:33 +00:00
<?php _e( 'Total:', 'woocommerce' ); ?>
<strong><?php echo $order->get_formatted_order_total(); ?></strong>
2011-08-10 17:11:11 +00:00
</li>
2012-03-05 13:25:02 +00:00
<?php if ($order->payment_method_title) : ?>
2011-08-10 17:11:11 +00:00
<li class="method">
2012-10-16 09:45:33 +00:00
<?php _e( 'Payment method:', 'woocommerce' ); ?>
2012-08-14 17:37:50 +00:00
<strong><?php
echo $order->payment_method_title;
2011-08-10 17:11:11 +00:00
?></strong>
</li>
2012-03-05 13:25:02 +00:00
<?php endif; ?>
2011-08-10 17:11:11 +00:00
</ul>
2012-08-14 17:37:50 +00:00
<?php do_action( 'woocommerce_receipt_' . $order->payment_method, $order_id ); ?>
2012-08-14 17:37:50 +00:00
2011-08-10 17:11:11 +00:00
<div class="clear"></div>
<?php
2012-08-14 17:37:50 +00:00
2012-02-08 17:45:01 +00:00
elseif (!in_array($order->status, array('pending', 'failed'))) :
2012-08-14 17:37:50 +00:00
2012-10-16 09:45:33 +00:00
$woocommerce->add_error( __( 'Your order has already been paid for. Please contact us if you need assistance.', 'woocommerce' ) );
2012-01-12 00:54:45 +00:00
$woocommerce->show_messages();
2012-08-14 17:37:50 +00:00
2011-08-10 17:11:11 +00:00
endif;
2012-08-14 17:37:50 +00:00
2011-08-10 17:11:11 +00:00
else :
2012-08-14 17:37:50 +00:00
2012-10-16 09:45:33 +00:00
$woocommerce->add_error( __( 'Invalid order.', 'woocommerce' ) );
2012-01-12 00:54:45 +00:00
$woocommerce->show_messages();
2012-08-14 17:37:50 +00:00
2011-08-10 17:11:11 +00:00
endif;
endif;
2012-08-14 17:37:50 +00:00
2012-02-08 17:45:01 +00:00
do_action('after_woocommerce_pay');
2011-08-10 17:11:11 +00:00
}