Some code cleanup and comments #1765

This commit is contained in:
Mike Jolley 2013-01-02 12:59:36 +00:00
parent c20e332863
commit 7bd2740ba2
4 changed files with 62 additions and 64 deletions

View File

@ -34,53 +34,58 @@ class WC_Shortcode_Pay {
public static function output( $atts ) {
global $woocommerce;
$woocommerce->nocache();
do_action('before_woocommerce_pay');
$woocommerce->show_messages();
// 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();
if ( isset($_GET['pay_for_order']) && isset($_GET['order']) && isset($_GET['order_id']) ) :
$woocommerce->nocache();
do_action( 'before_woocommerce_pay' );
$woocommerce->show_messages();
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 = new WC_Order( $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,22 +116,22 @@ 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');
do_action( 'after_woocommerce_pay' );
}
}

View File

@ -53,7 +53,7 @@ global $woocommerce;
<?php if ($order->order_total > 0) : ?>
<ul class="payment_methods methods">
<?php
if ($available_gateways) :
if ( $available_gateways ) :
// Chosen Method
if (sizeof($available_gateways)) current($available_gateways)->set_current();
foreach ($available_gateways as $gateway ) :

View File

@ -185,25 +185,22 @@ $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) :
if ( ! empty( $available_gateways ) ) {
// Chosen Method
if (sizeof($available_gateways)) :
$default_gateway = get_option('woocommerce_default_gateway');
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[ get_option( 'woocommerce_default_gateway' ) ] ) ) {
$available_gateways[ get_option( 'woocommerce_default_gateway' ) ]->set_current();
} else {
current( $available_gateways )->set_current();
}
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();
} 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 ); ?> />
<label for="payment_method_<?php echo $gateway->id; ?>"><?php echo $gateway->get_title(); ?> <?php echo $gateway->get_icon(); ?></label>
<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 ); ?> />
<label for="payment_method_<?php echo $gateway->id; ?>"><?php echo $gateway->get_title(); ?> <?php echo $gateway->get_icon(); ?></label>
<?php
if ( $gateway->has_fields() || $gateway->get_description() ) :
echo '<div class="payment_box payment_method_' . $gateway->id . '" ' . ( $gateway->chosen ? '' : 'style="display:none;"' ) . '>';
@ -213,16 +210,15 @@ $available_methods = $woocommerce->shipping->get_available_shipping_methods();
?>
</li>
<?php
endforeach;
else :
}
} else {
if ( !$woocommerce->customer->get_country() ) :
echo '<p>'.__( 'Please fill in your details above to see available payment methods.', 'woocommerce' ).'</p>';
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;
if ( ! $woocommerce->customer->get_country() )
echo '<p>' . __( 'Please fill in your details above to see available payment methods.', 'woocommerce' ) . '</p>';
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;
}
?>
</ul>
<?php endif; ?>

View File

@ -4,34 +4,33 @@
*
* @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'))) : ?>
<?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>
<a href="<?php echo esc_url( $order->get_checkout_payment_url() ); ?>" class="button pay"><?php _e( 'Pay', 'woocommerce' ) ?></a>
<?php if (is_user_logged_in()) : ?>
<a href="<?php echo esc_url( get_permalink(woocommerce_get_page_id('myaccount')) ); ?>" class="button pay"><?php _e( 'My Account', 'woocommerce' ); ?></a>
<?php if ( is_user_logged_in() ) : ?>
<a href="<?php echo esc_url( get_permalink( woocommerce_get_page_id( 'myaccount' ) ) ); ?>" class="button pay"><?php _e( 'My Account', 'woocommerce' ); ?></a>
<?php endif; ?>
</p>
@ -46,18 +45,16 @@ $available_gateways = $woocommerce->payment_gateways->get_available_payment_gate
</li>
<li class="date">
<?php _e( 'Date:', 'woocommerce' ); ?>
<strong><?php echo date_i18n(get_option('date_format'), strtotime($order->order_date)); ?></strong>
<strong><?php echo date_i18n( get_option( 'date_format' ), strtotime( $order->order_date ) ); ?></strong>
</li>
<li class="total">
<?php _e( 'Total:', 'woocommerce' ); ?>
<strong><?php echo $order->get_formatted_order_total(); ?></strong>
</li>
<?php if ($order->payment_method_title) : ?>
<?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>