Some code cleanup and comments #1765
This commit is contained in:
parent
c20e332863
commit
7bd2740ba2
|
@ -34,53 +34,58 @@ class WC_Shortcode_Pay {
|
|||
public static function output( $atts ) {
|
||||
global $woocommerce;
|
||||
|
||||
// Get available gateways here - touching this also ensures gateways are loaded in time for the woocommerce_receipt_ hook
|
||||
$available_gateways = $woocommerce->payment_gateways->get_available_payment_gateways();
|
||||
|
||||
$woocommerce->nocache();
|
||||
|
||||
do_action( 'before_woocommerce_pay' );
|
||||
|
||||
$woocommerce->show_messages();
|
||||
$available_gateways = $woocommerce->payment_gateways->get_available_payment_gateways();
|
||||
|
||||
if ( isset($_GET['pay_for_order']) && isset($_GET['order']) && isset($_GET['order_id']) ) :
|
||||
if ( isset( $_GET['pay_for_order'] ) && isset( $_GET['order'] ) && isset( $_GET['order_id'] ) ) {
|
||||
|
||||
// Pay for existing order
|
||||
$order_key = urldecode( $_GET['order'] );
|
||||
$order_id = (int) $_GET['order_id'];
|
||||
$order_id = absint( $_GET['order_id'] );
|
||||
$order = new WC_Order( $order_id );
|
||||
|
||||
if ($order->id == $order_id && $order->order_key == $order_key && in_array($order->status, array('pending', 'failed'))) :
|
||||
if ( $order->id == $order_id && $order->order_key == $order_key && in_array( $order->status, array( 'pending', 'failed' ) ) ) {
|
||||
|
||||
// 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 );
|
||||
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 );
|
||||
|
||||
// Show form
|
||||
woocommerce_get_template( 'checkout/form-pay.php', array( 'order' => $order, 'available_gateways' => $available_gateways ) );
|
||||
|
||||
elseif (!in_array($order->status, array('pending', 'failed'))) :
|
||||
} elseif ( ! in_array( $order->status, array( 'pending', 'failed' ) ) ) {
|
||||
|
||||
$woocommerce->add_error( __( 'Your order has already been paid for. Please contact us if you need assistance.', 'woocommerce' ) );
|
||||
$woocommerce->show_messages();
|
||||
|
||||
else :
|
||||
} else {
|
||||
|
||||
$woocommerce->add_error( __( 'Invalid order.', 'woocommerce' ) );
|
||||
$woocommerce->show_messages();
|
||||
|
||||
endif;
|
||||
}
|
||||
|
||||
else :
|
||||
} else {
|
||||
|
||||
// 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 = '';
|
||||
$order_id = isset( $_GET['order'] ) ? absint( $_GET['order'] ) : 0;
|
||||
$order_key = isset( $_GET['key'] ) ? woocommerce_clean( $_GET['key'] ) : '';
|
||||
|
||||
if ($order_id > 0) :
|
||||
if ( $order_id > 0 ) {
|
||||
|
||||
$order = new WC_Order( $order_id );
|
||||
|
||||
if ($order->order_key == $order_key && in_array($order->status, array('pending', 'failed'))) :
|
||||
if ( $order->order_key == $order_key && in_array( $order->status, array( 'pending', 'failed' ) ) ) {
|
||||
|
||||
?>
|
||||
<ul class="order_details">
|
||||
|
@ -111,21 +116,21 @@ class WC_Shortcode_Pay {
|
|||
<div class="clear"></div>
|
||||
<?php
|
||||
|
||||
elseif (!in_array($order->status, array('pending', 'failed'))) :
|
||||
} elseif ( ! in_array( $order->status, array( 'pending', 'failed' ) ) ) {
|
||||
|
||||
$woocommerce->add_error( __( 'Your order has already been paid for. Please contact us if you need assistance.', 'woocommerce' ) );
|
||||
$woocommerce->show_messages();
|
||||
|
||||
endif;
|
||||
}
|
||||
|
||||
else :
|
||||
} else {
|
||||
|
||||
$woocommerce->add_error( __( 'Invalid order.', 'woocommerce' ) );
|
||||
$woocommerce->show_messages();
|
||||
|
||||
endif;
|
||||
}
|
||||
|
||||
endif;
|
||||
}
|
||||
|
||||
do_action( 'after_woocommerce_pay' );
|
||||
}
|
||||
|
|
|
@ -185,21 +185,18 @@ $available_methods = $woocommerce->shipping->get_available_shipping_methods();
|
|||
<ul class="payment_methods methods">
|
||||
<?php
|
||||
$available_gateways = $woocommerce->payment_gateways->get_available_payment_gateways();
|
||||
if ($available_gateways) :
|
||||
// Chosen Method
|
||||
if (sizeof($available_gateways)) :
|
||||
$default_gateway = get_option('woocommerce_default_gateway');
|
||||
if ( ! empty( $available_gateways ) ) {
|
||||
|
||||
// Chosen Method
|
||||
if ( isset( $woocommerce->session->chosen_payment_method ) && isset( $available_gateways[ $woocommerce->session->chosen_payment_method ] ) ) {
|
||||
$available_gateways[ $woocommerce->session->chosen_payment_method ]->set_current();
|
||||
} elseif ( isset( $available_gateways[ $default_gateway ] ) ) {
|
||||
$available_gateways[ $default_gateway ]->set_current();
|
||||
} elseif ( isset( $available_gateways[ get_option( 'woocommerce_default_gateway' ) ] ) ) {
|
||||
$available_gateways[ get_option( 'woocommerce_default_gateway' ) ]->set_current();
|
||||
} else {
|
||||
current( $available_gateways )->set_current();
|
||||
}
|
||||
|
||||
endif;
|
||||
foreach ($available_gateways as $gateway ) :
|
||||
foreach ( $available_gateways as $gateway ) {
|
||||
?>
|
||||
<li>
|
||||
<input type="radio" id="payment_method_<?php echo $gateway->id; ?>" class="input-radio" name="payment_method" value="<?php echo esc_attr( $gateway->id ); ?>" <?php checked( $gateway->chosen, true ); ?> />
|
||||
|
@ -213,16 +210,15 @@ $available_methods = $woocommerce->shipping->get_available_shipping_methods();
|
|||
?>
|
||||
</li>
|
||||
<?php
|
||||
endforeach;
|
||||
else :
|
||||
}
|
||||
} else {
|
||||
|
||||
if ( !$woocommerce->customer->get_country() ) :
|
||||
if ( ! $woocommerce->customer->get_country() )
|
||||
echo '<p>' . __( 'Please fill in your details above to see available payment methods.', 'woocommerce' ) . '</p>';
|
||||
else :
|
||||
else
|
||||
echo '<p>' . __( 'Sorry, it seems that there are no available payment methods for your state. Please contact us if you require assistance or wish to make alternate arrangements.', 'woocommerce' ) . '</p>';
|
||||
endif;
|
||||
|
||||
endif;
|
||||
}
|
||||
?>
|
||||
</ul>
|
||||
<?php endif; ?>
|
||||
|
|
|
@ -4,28 +4,27 @@
|
|||
*
|
||||
* @author WooThemes
|
||||
* @package WooCommerce/Templates
|
||||
* @version 1.6.4
|
||||
* @version 2.0.0
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
global $woocommerce;
|
||||
|
||||
// Get available gateways here - touching this also ensures gateways are loaded in time for the woocommerce_thankyou_ hook
|
||||
$available_gateways = $woocommerce->payment_gateways->get_available_payment_gateways();
|
||||
?>
|
||||
|
||||
<?php if ($order) : ?>
|
||||
if ( $order ) : ?>
|
||||
|
||||
<?php if ( in_array( $order->status, array( 'failed' ) ) ) : ?>
|
||||
|
||||
<p><?php _e( 'Unfortunately your order cannot be processed as the originating bank/merchant has declined your transaction.', 'woocommerce' ); ?></p>
|
||||
|
||||
<p><?php
|
||||
if (is_user_logged_in()) :
|
||||
if ( is_user_logged_in() )
|
||||
_e( 'Please attempt your purchase again or go to your account page.', 'woocommerce' );
|
||||
else :
|
||||
else
|
||||
_e( 'Please attempt your purchase again.', 'woocommerce' );
|
||||
endif;
|
||||
?></p>
|
||||
|
||||
<p>
|
||||
|
@ -55,9 +54,7 @@ $available_gateways = $woocommerce->payment_gateways->get_available_payment_gate
|
|||
<?php if ( $order->payment_method_title ) : ?>
|
||||
<li class="method">
|
||||
<?php _e( 'Payment method:', 'woocommerce' ); ?>
|
||||
<strong><?php
|
||||
echo $order->payment_method_title;
|
||||
?></strong>
|
||||
<strong><?php echo $order->payment_method_title; ?></strong>
|
||||
</li>
|
||||
<?php endif; ?>
|
||||
</ul>
|
||||
|
|
Loading…
Reference in New Issue