Permalink
Browse files

Improved template loader

  • Loading branch information...
mikejolley committed Feb 3, 2012
1 parent 85f6d53 commit 3b5272e72e6d222560fde6be37bfbc8516f2161a
@@ -62,12 +62,12 @@ function __construct () {
/** Output the billing information form */
function checkout_form_billing() {
- include( woocommerce_locate_template( 'checkout/form-billing.php' ) );
+ woocommerce_get_template( 'checkout/form-billing.php', array( 'checkout' => $this ) );
}
/** Output the shipping information form */
function checkout_form_shipping() {
- include( woocommerce_locate_template( 'checkout/form-shipping.php' ) );
+ woocommerce_get_template( 'checkout/form-shipping.php', array( 'checkout' => $this ) );
}
/**
View
@@ -66,12 +66,12 @@ function get_content_type() {
return 'text/html';
}
- function email_header() {
- woocommerce_get_template('emails/email-header.php', false);
+ function email_header( $email_heading ) {
+ woocommerce_get_template('emails/email-header.php', array( 'email_heading' => $email_heading ));
}
function email_footer() {
- woocommerce_get_template('emails/email-footer.php', false);
+ woocommerce_get_template('emails/email-footer.php');
}
/**
@@ -81,7 +81,7 @@ function wrap_message( $email_heading, $message ) {
// Buffer
ob_start();
- do_action('woocommerce_email_header');
+ do_action('woocommerce_email_header', $email_heading);
echo wpautop(wptexturize( $message ));
@@ -114,7 +114,6 @@ function send( $to, $subject, $message, $headers = "", $attachments = "" ) {
* New order
**/
function new_order( $order_id ) {
- global $order, $email_heading;
$order = new WC_Order( $order_id );
@@ -128,7 +127,10 @@ function new_order( $order_id ) {
ob_start();
// Get mail template
- woocommerce_get_template('emails/admin-new-order.php', false);
+ woocommerce_get_template('emails/admin-new-order.php', array(
+ 'order' => $order,
+ 'email_heading' => $email_heading
+ ));
// Get contents
$message = ob_get_clean();
@@ -141,7 +143,6 @@ function new_order( $order_id ) {
* Processing Order
**/
function customer_processing_order( $order_id ) {
- global $order, $email_heading;
$order = new WC_Order( $order_id );
@@ -155,7 +156,10 @@ function customer_processing_order( $order_id ) {
ob_start();
// Get mail template
- woocommerce_get_template('emails/customer-processing-order.php', false);
+ woocommerce_get_template('emails/customer-processing-order.php', array(
+ 'order' => $order,
+ 'email_heading' => $email_heading
+ ));
// Get contents
$message = ob_get_clean();
@@ -171,7 +175,6 @@ function customer_processing_order( $order_id ) {
* Completed Order
**/
function customer_completed_order( $order_id ) {
- global $order, $email_heading;
$order = new WC_Order( $order_id );
@@ -193,7 +196,10 @@ function customer_completed_order( $order_id ) {
ob_start();
// Get mail template
- woocommerce_get_template('emails/customer-completed-order.php', false);
+ woocommerce_get_template('emails/customer-completed-order.php', array(
+ 'order' => $order,
+ 'email_heading' => $email_heading
+ ));
// Get contents
$message = ob_get_clean();
@@ -209,7 +215,6 @@ function customer_completed_order( $order_id ) {
* Pay for order - invoice
**/
function customer_invoice( $pay_for_order ) {
- global $order, $email_heading;
$order = $pay_for_order;
@@ -223,7 +228,10 @@ function customer_invoice( $pay_for_order ) {
ob_start();
// Get mail template
- woocommerce_get_template('emails/customer-invoice.php', false);
+ woocommerce_get_template('emails/customer-invoice.php', array(
+ 'order' => $order,
+ 'email_heading' => $email_heading
+ ));
// Get contents
$message = ob_get_clean();
@@ -239,7 +247,6 @@ function customer_invoice( $pay_for_order ) {
* Customer notes
**/
function customer_note( $args ) {
- global $order, $email_heading, $customer_note;
$defaults = array(
'order_id' => '',
@@ -264,7 +271,11 @@ function customer_note( $args ) {
ob_start();
// Get mail template
- woocommerce_get_template('emails/customer-note.php', false);
+ woocommerce_get_template('emails/customer-note.php', array(
+ 'order' => $order,
+ 'email_heading' => $email_heading,
+ 'customer_note' => $customer_note
+ ));
// Get contents
$message = ob_get_clean();
@@ -362,7 +373,6 @@ function order_meta( $order, $sent_to_admin ) {
* Customer new account welcome email
**/
function customer_new_account( $user_id, $plaintext_pass ) {
- global $user_login, $user_pass, $blogname;
if (!$user_id || !$plaintext_pass) return;
@@ -381,7 +391,12 @@ function customer_new_account( $user_id, $plaintext_pass ) {
ob_start();
// Get mail template
- woocommerce_get_template('emails/customer-new-account.php', false);
+ woocommerce_get_template('emails/customer-new-account.php', array(
+ 'user_login' => $user_login,
+ 'user_pass' => $user_pass,
+ 'blogname' => $blogname,
+ 'email_heading' => $email_heading
+ ));
// Get contents
$message = ob_get_clean();
View
@@ -84,6 +84,7 @@ Yes you can! Join in on our GitHub repository :) https://github.com/woothemes/wo
= 1.4.2 =
* Uninstall fix
+* Improved template loader - passes args instead of using globals
= 1.4.1 - 01/02/2012 =
* Depreciated tax class fix
@@ -25,5 +25,5 @@ function woocommerce_checkout( $atts ) {
if ( $woocommerce->error_count()==0 && $non_js_checkout) $woocommerce->add_message( __('The order totals have been updated. Please confirm your order by pressing the Place Order button at the bottom of the page.', 'woocommerce') );
- woocommerce_get_template('checkout/form-checkout.php', false);
+ woocommerce_get_template('checkout/form-checkout.php');
}
@@ -36,7 +36,7 @@ function get_woocommerce_view_order() {
* @since 1.4
*/
function woocommerce_my_account( $atts ) {
- global $woocommerce, $current_user, $recent_orders;
+ global $woocommerce, $current_user;
if ( ! is_user_logged_in() ) :
@@ -52,7 +52,10 @@ function woocommerce_my_account( $atts ) {
get_currentuserinfo();
- woocommerce_get_template( 'myaccount/my-account.php' );
+ woocommerce_get_template( 'myaccount/my-account.php', array(
+ 'current_user' => $current_user,
+ 'recent_orders' => $recent_orders
+ ) );
endif;
@@ -70,15 +73,18 @@ function woocommerce_my_account( $atts ) {
* @since 1.4
*/
function woocommerce_edit_address() {
- global $woocommerce, $load_address, $address;
+ global $woocommerce;
if ( ! is_user_logged_in() ) return;
$load_address = woocommerce_get_address_to_edit();
$address = $woocommerce->countries->get_address_fields( get_user_meta( get_current_user_id(), $load_address . '_country', true ), $load_address . '_' );
- woocommerce_get_template( 'myaccount/form-edit-address.php' );
+ woocommerce_get_template( 'myaccount/form-edit-address.php', array(
+ 'load_address' => $load_address,
+ 'address' => $address
+ ) );
}
/**
@@ -14,7 +14,7 @@ function get_woocommerce_order_tracking($atts) {
}
function woocommerce_order_tracking( $atts ) {
- global $woocommerce, $order;
+ global $woocommerce;
extract(shortcode_atts(array(
), $atts));
@@ -34,7 +34,9 @@ function woocommerce_order_tracking( $atts ) {
if ($order->billing_email == $order_email) :
- woocommerce_get_template( 'order/tracking.php' );
+ woocommerce_get_template( 'order/tracking.php', array(
+ 'order' => $order
+ ) );
return;
@@ -18,7 +18,7 @@ function get_woocommerce_pay( $atts ) {
* Outputs the pay page - payment gateways can hook in here to show payment forms etc
**/
function woocommerce_pay() {
- global $woocommerce, $order;
+ global $woocommerce;
if ( isset($_GET['pay_for_order']) && isset($_GET['order']) && isset($_GET['order_id']) ) :
@@ -35,7 +35,7 @@ function woocommerce_pay() {
if ($order->billing_postcode) $woocommerce->customer->set_postcode( $order->billing_postcode );
// Show form
- woocommerce_get_template('checkout/form-pay.php');
+ woocommerce_get_template('checkout/form-pay.php', array('order' => $order));
elseif (!in_array($order->status, array('pending', 'failed'))) :
@@ -18,7 +18,7 @@ function get_woocommerce_thankyou( $atts ) {
* Outputs the order received page
**/
function woocommerce_thankyou( $atts ) {
- global $woocommerce, $order;
+ global $woocommerce;
$order = false;
@@ -36,5 +36,5 @@ function woocommerce_thankyou( $atts ) {
endif;
endif;
- woocommerce_get_template( 'checkout/thankyou.php' );
+ woocommerce_get_template( 'checkout/thankyou.php', array( 'order' => $order ) );
}
@@ -15,22 +15,22 @@
<?php endif; ?>
-<?php do_action('woocommerce_before_checkout_billing_form', $this); ?>
+<?php do_action('woocommerce_before_checkout_billing_form', $checkout); ?>
-<?php foreach ($this->checkout_fields['billing'] as $key => $field) : ?>
+<?php foreach ($checkout->checkout_fields['billing'] as $key => $field) : ?>
- <?php woocommerce_form_field( $key, $field, $this->get_value( $key ) ); ?>
+ <?php woocommerce_form_field( $key, $field, $checkout->get_value( $key ) ); ?>
<?php endforeach; ?>
-<?php do_action('woocommerce_after_checkout_billing_form', $this); ?>
+<?php do_action('woocommerce_after_checkout_billing_form', $checkout); ?>
<?php if (!is_user_logged_in() && get_option('woocommerce_enable_signup_and_login_from_checkout')=="yes") : ?>
<?php if (get_option('woocommerce_enable_guest_checkout')=='yes') : ?>
<p class="form-row">
- <input class="input-checkbox" id="createaccount" <?php checked($this->get_value('createaccount'), true) ?> type="checkbox" name="createaccount" value="1" /> <label for="createaccount" class="checkbox"><?php _e('Create an account?', 'woocommerce'); ?></label>
+ <input class="input-checkbox" id="createaccount" <?php checked($checkout->get_value('createaccount'), true) ?> type="checkbox" name="createaccount" value="1" /> <label for="createaccount" class="checkbox"><?php _e('Create an account?', 'woocommerce'); ?></label>
</p>
<?php endif; ?>
@@ -39,9 +39,9 @@
<p><?php _e('Create an account by entering the information below. If you are a returning customer please login with your username at the top of the page.', 'woocommerce'); ?></p>
- <?php foreach ($this->checkout_fields['account'] as $key => $field) : ?>
+ <?php foreach ($checkout->checkout_fields['account'] as $key => $field) : ?>
- <?php woocommerce_form_field( $key, $field, $this->get_value( $key ) ); ?>
+ <?php woocommerce_form_field( $key, $field, $checkout->get_value( $key ) ); ?>
<?php endforeach; ?>
@@ -2,7 +2,7 @@
/**
* Pay for order form
*/
-global $order, $woocommerce;
+global $woocommerce;
?>
<form id="order_review" method="post">
@@ -15,7 +15,7 @@
else :
- $shiptobilling = $this->get_value('shiptobilling');
+ $shiptobilling = $checkout->get_value('shiptobilling');
endif;
?>
@@ -28,21 +28,21 @@
<div class="shipping_address">
- <?php do_action('woocommerce_before_checkout_shipping_form', $this); ?>
+ <?php do_action('woocommerce_before_checkout_shipping_form', $checkout); ?>
- <?php foreach ($this->checkout_fields['shipping'] as $key => $field) : ?>
+ <?php foreach ($checkout->checkout_fields['shipping'] as $key => $field) : ?>
- <?php woocommerce_form_field( $key, $field, $this->get_value( $key ) ); ?>
+ <?php woocommerce_form_field( $key, $field, $checkout->get_value( $key ) ); ?>
<?php endforeach; ?>
- <?php do_action('woocommerce_after_checkout_shipping_form', $this); ?>
+ <?php do_action('woocommerce_after_checkout_shipping_form', $checkout); ?>
</div>
<?php endif; ?>
-<?php do_action('woocommerce_before_order_notes', $this); ?>
+<?php do_action('woocommerce_before_order_notes', $checkout); ?>
<?php if (get_option('woocommerce_enable_order_comments')!='no') : ?>
@@ -52,12 +52,12 @@
<?php endif; ?>
- <?php foreach ($this->checkout_fields['order'] as $key => $field) : ?>
+ <?php foreach ($checkout->checkout_fields['order'] as $key => $field) : ?>
- <?php woocommerce_form_field( $key, $field, $this->get_value( $key ) ); ?>
+ <?php woocommerce_form_field( $key, $field, $checkout->get_value( $key ) ); ?>
<?php endforeach; ?>
<?php endif; ?>
-<?php do_action('woocommerce_after_order_notes', $this); ?>
+<?php do_action('woocommerce_after_order_notes', $checkout); ?>
@@ -3,7 +3,7 @@
* Thankyou Page
*/
-global $woocommerce, $order;
+global $woocommerce;
?>
<?php if ($order) : ?>
@@ -1,8 +1,6 @@
<?php if (!defined('ABSPATH')) exit; ?>
-<?php global $order; ?>
-
-<?php do_action('woocommerce_email_header'); ?>
+<?php do_action('woocommerce_email_header', $email_heading); ?>
<p><?php echo __('You have received an order from', 'woocommerce') . ' ' . $order->billing_first_name . ' ' . $order->billing_last_name . __(". Their order is as follows:", 'woocommerce'); ?></p>
Oops, something went wrong.

0 comments on commit 3b5272e

Please sign in to comment.