Skip to content

Commit

Permalink
Made product global, setup automatically, and removed the need to cal…
Browse files Browse the repository at this point in the history
…l the class directly in the loop

Themes need checking for compat, but the change makes it easier to use
  • Loading branch information
mikejolley committed Dec 11, 2011
1 parent b7688bc commit 35d1d56
Show file tree
Hide file tree
Showing 20 changed files with 156 additions and 114 deletions.
4 changes: 2 additions & 2 deletions classes/woocommerce_email.class.php
Expand Up @@ -226,7 +226,7 @@ function customer_note( $args ) {

$args = wp_parse_args( $args, $defaults );

extract( $args, EXTR_SKIP );
extract( $args );

if (!$order_id || !$customer_note) return;

Expand Down Expand Up @@ -296,7 +296,7 @@ function backorder( $args ) {

$args = wp_parse_args( $args, $defaults );

extract( $args, EXTR_SKIP );
extract( $args );

if (!$product || !$quantity) return;

Expand Down
1 change: 1 addition & 0 deletions readme.txt
Expand Up @@ -87,6 +87,7 @@ Yes you can! Join in on our GitHub repository :) https://github.com/woothemes/wo
* Moved many shortcodes (contents) to template files for easier customisation
* Moved woocommerce class into the main file
* Category ordering fix
* Made 'product' global, and auto filled when calling the_post - also remove this from the hooks. Certain themes may need to be updated.

= 1.3.2 - 09/12/2011 =
* Fixed error when adding an order manually
Expand Down
10 changes: 5 additions & 5 deletions templates/loop-shop.php
Expand Up @@ -19,9 +19,9 @@

if ($woocommerce_loop['show_products'] && have_posts()) : while (have_posts()) : the_post();

$_product = &new woocommerce_product( $post->ID );
global $product;

if (!$_product->is_visible()) continue;
if (!$product->is_visible()) continue;

$woocommerce_loop['loop']++;

Expand All @@ -32,15 +32,15 @@

<a href="<?php the_permalink(); ?>">

<?php do_action('woocommerce_before_shop_loop_item_title', $post, $_product); ?>
<?php do_action('woocommerce_before_shop_loop_item_title'); ?>

<h3><?php the_title(); ?></h3>

<?php do_action('woocommerce_after_shop_loop_item_title', $post, $_product); ?>
<?php do_action('woocommerce_after_shop_loop_item_title'); ?>

</a>

<?php do_action('woocommerce_after_shop_loop_item', $post, $_product); ?>
<?php do_action('woocommerce_after_shop_loop_item'); ?>

</li><?php

Expand Down
12 changes: 12 additions & 0 deletions templates/loop/sale_flash.php
@@ -0,0 +1,12 @@
<?php
/**
* Product Loop Sale Flash
*/

global $post, $product;
?>
<?php if ($product->is_on_sale()) : ?>

<?php echo apply_filters('woocommerce_sale_flash', '<span class="onsale">'.__('Sale!', 'woothemes').'</span>', $post, $product); ?>

<?php endif; ?>
14 changes: 7 additions & 7 deletions templates/single-product.php
Expand Up @@ -2,31 +2,31 @@

<?php do_action('woocommerce_before_main_content'); ?>

<?php if ( have_posts() ) while ( have_posts() ) : the_post(); global $_product; $_product = &new woocommerce_product( $post->ID ); ?>
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>

<?php do_action('woocommerce_before_single_product', $post, $_product); ?>
<?php do_action('woocommerce_before_single_product'); ?>

<div itemscope itemtype="http://schema.org/Product" id="product-<?php the_ID(); ?>" <?php post_class(); ?>>

<?php do_action('woocommerce_before_single_product_summary', $post, $_product); ?>
<?php do_action('woocommerce_before_single_product_summary'); ?>

<div class="summary">

<h1 itemprop="name" class="product_title page-title"><?php the_title(); ?></h1>

<?php do_action( 'woocommerce_single_product_summary', $post, $_product ); ?>
<?php do_action( 'woocommerce_single_product_summary'); ?>

</div>

<?php do_action('woocommerce_after_single_product_summary', $post, $_product); ?>
<?php do_action('woocommerce_after_single_product_summary'); ?>

</div>

<?php do_action('woocommerce_after_single_product', $post, $_product); ?>
<?php do_action('woocommerce_after_single_product'); ?>

<?php endwhile; ?>

<?php do_action('woocommerce_after_main_content'); // </div></div> ?>
<?php do_action('woocommerce_after_main_content'); ?>

<?php do_action('woocommerce_sidebar'); ?>

Expand Down
4 changes: 2 additions & 2 deletions templates/single-product/add-to-cart/external.php
Expand Up @@ -3,9 +3,9 @@
* External Add to Cart
*/

global $woocommerce;
global $woocommerce, $product;

$product_url = get_post_meta( $_product->id, 'product_url', true );
$product_url = get_post_meta( $product->id, 'product_url', true );

if (!$product_url) return;
?>
Expand Down
8 changes: 4 additions & 4 deletions templates/single-product/add-to-cart/grouped.php
Expand Up @@ -3,17 +3,17 @@
* Grouped Product Add to Cart
*/

global $woocommerce, $_product;
global $woocommerce, $product;
?>

<?php do_action('woocommerce_before_add_to_cart_form'); ?>

<form action="<?php echo esc_url( $_product->add_to_cart_url() ); ?>" class="cart" method="post" enctype='multipart/form-data'>
<form action="<?php echo esc_url( $product->add_to_cart_url() ); ?>" class="cart" method="post" enctype='multipart/form-data'>
<table cellspacing="0" class="group_table">
<tbody>
<?php foreach ($_product->get_children() as $child_id) : $child_product = $_product->get_child( $child_id ); $cavailability = $child_product->get_availability(); ?>
<?php foreach ($product->get_children() as $child_id) : $child_product = $product->get_child( $child_id ); $cavailability = $child_product->get_availability(); ?>
<tr>
<td><?php woocommerce_quantity_input( 'quantity['.$child_product->id.']' ); ?></td>
<td><?php woocommerce_quantity_input( array( 'input_name' => 'quantity['.$child_product->id.']', 'input_value' => '0' ) ); ?></td>
<td><label for="product-<?php echo $child_product->id; ?>"><?php
if ($child_product->is_visible()) echo '<a href="'.get_permalink($child_product->id).'">';
echo $child_product->get_title();
Expand Down
4 changes: 2 additions & 2 deletions templates/single-product/add-to-cart/quantity.php
Expand Up @@ -3,6 +3,6 @@
* Single Product Quantity Inputs
*/

global $post, $_product, $name, $value;
global $input_name, $input_value;
?>
<div class="quantity"><input name="<?php echo $name; ?>" value="<?php echo $value; ?>" size="4" title="Qty" class="input-text qty text" maxlength="12" /></div>
<div class="quantity"><input name="<?php echo $input_name; ?>" value="<?php echo $input_value; ?>" size="4" title="Qty" class="input-text qty text" maxlength="12" /></div>
12 changes: 6 additions & 6 deletions templates/single-product/add-to-cart/simple.php
Expand Up @@ -3,32 +3,32 @@
* Simple Product Add to Cart
*/

global $woocommerce, $_product;
global $woocommerce, $product;

if( $_product->get_price() === '') return;
if( $product->get_price() === '') return;
?>

<?php
$availability = $_product->get_availability();
$availability = $product->get_availability();

if ($availability['availability']) :
echo apply_filters( 'woocommerce_stock_html', '<p class="stock '.$availability['class'].'">'.$availability['availability'].'</p>', $availability['availability'] );
endif;
?>

<?php if (!$_product->is_in_stock()) : ?>
<?php if (!$product->is_in_stock()) : ?>
<link itemprop="availability" href="http://schema.org/OutOfStock">
<?php else : ?>

<link itemprop="availability" href="http://schema.org/InStock">

<?php do_action('woocommerce_before_add_to_cart_form'); ?>

<form action="<?php echo esc_url( $_product->add_to_cart_url() ); ?>" class="cart" method="post" enctype='multipart/form-data'>
<form action="<?php echo esc_url( $product->add_to_cart_url() ); ?>" class="cart" method="post" enctype='multipart/form-data'>

<?php do_action('woocommerce_before_add_to_cart_button'); ?>

<?php if (!$_product->is_downloadable()) woocommerce_quantity_input(); ?>
<?php if (!$product->is_downloadable()) woocommerce_quantity_input(); ?>

<button type="submit" class="button alt"><?php _e('Add to cart', 'woothemes'); ?></button>

Expand Down
4 changes: 2 additions & 2 deletions templates/single-product/add-to-cart/variable.php
Expand Up @@ -3,15 +3,15 @@
* Variable Product Add to Cart
*/

global $woocommerce, $_product, $available_variations, $attributes, $selected_attributes;
global $woocommerce, $product, $available_variations, $attributes, $selected_attributes;
?>
<script type="text/javascript">
var product_variations = <?php echo json_encode($available_variations) ?>;
</script>

<?php do_action('woocommerce_before_add_to_cart_form'); ?>

<form action="<?php echo esc_url( $_product->add_to_cart_url() ); ?>" class="variations_form cart" method="post" enctype='multipart/form-data'>
<form action="<?php echo esc_url( $product->add_to_cart_url() ); ?>" class="variations_form cart" method="post" enctype='multipart/form-data'>
<table class="variations" cellspacing="0">
<tbody>
<?php foreach ($attributes as $name => $options) : ?>
Expand Down
10 changes: 5 additions & 5 deletions templates/single-product/meta.php
Expand Up @@ -3,16 +3,16 @@
* Single Product Meta
*/

global $post, $_product;
global $post, $product;
?>
<div class="product_meta">

<?php if ($_product->is_type('simple') && get_option('woocommerce_enable_sku')=='yes') : ?>
<span itemprop="productID" class="sku"><?php _e('SKU:', 'woothemes'); ?> <?php echo $_product->sku; ?>.</span>
<?php if ($product->is_type('simple') && get_option('woocommerce_enable_sku')=='yes') : ?>
<span itemprop="productID" class="sku"><?php _e('SKU:', 'woothemes'); ?> <?php echo $product->sku; ?>.</span>
<?php endif; ?>

<?php echo $_product->get_categories( ', ', ' <span class="posted_in">'.__('Category:', 'woothemes').' ', '.</span>'); ?>
<?php echo $product->get_categories( ', ', ' <span class="posted_in">'.__('Category:', 'woothemes').' ', '.</span>'); ?>

<?php echo $_product->get_tags( ', ', ' <span class="tagged_as">'.__('Tags:', 'woothemes').' ', '.</span>'); ?>
<?php echo $product->get_tags( ', ', ' <span class="tagged_as">'.__('Tags:', 'woothemes').' ', '.</span>'); ?>

</div>
4 changes: 2 additions & 2 deletions templates/single-product/price.php
Expand Up @@ -3,6 +3,6 @@
* Single Product Price
*/

global $post, $_product;
global $post, $product;
?>
<p itemprop="price" class="price"><?php echo $_product->get_price_html(); ?></p>
<p itemprop="price" class="price"><?php echo $product->get_price_html(); ?></p>
12 changes: 12 additions & 0 deletions templates/single-product/sale_flash.php
@@ -0,0 +1,12 @@
<?php
/**
* Single Product Sale Flash
*/

global $post, $product;
?>
<?php if ($product->is_on_sale()) : ?>

<?php echo apply_filters('woocommerce_sale_flash', '<span class="onsale">'.__('Sale!', 'woothemes').'</span>', $post, $product); ?>

<?php endif; ?>
2 changes: 0 additions & 2 deletions templates/single-product/share.php
Expand Up @@ -2,8 +2,6 @@
/**
* Single Product Share
*/

global $post, $_product;
?>

<?php if (get_option('woocommerce_sharethis')) : ?>
Expand Down
4 changes: 2 additions & 2 deletions templates/single-product/tabs/attributes.php
Expand Up @@ -3,14 +3,14 @@
* Attributes Tab
*/

global $woocommerce, $post, $_product;
global $woocommerce, $post, $product;
?>
<div class="panel" id="tab-attributes">

<?php $heading = apply_filters('woocommerce_product_additional_information_heading', __('Additional Information', 'woothemes')); ?>

<h2><?php echo $heading; ?></h2>

<?php $_product->list_attributes(); ?>
<?php $product->list_attributes(); ?>

</div>
2 changes: 1 addition & 1 deletion widgets/widget-layered_nav.php
Expand Up @@ -175,7 +175,7 @@ function widget( $args, $instance ) {
echo "<ul>";

// Force found when option is selected
if (array_key_exists($taxonomy, $_chosen_attributes)) $found = true;
if (is_array($_chosen_attributes) && array_key_exists($taxonomy, $_chosen_attributes)) $found = true;

foreach ($terms as $term) {

Expand Down
2 changes: 1 addition & 1 deletion woocommerce-core-functions.php
Expand Up @@ -8,7 +8,7 @@
* @category Core
* @author WooThemes
*/

/**
* HTML emails from WooCommerce
**/
Expand Down
31 changes: 15 additions & 16 deletions woocommerce-hooks.php
Expand Up @@ -17,8 +17,8 @@
add_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10);

/* Sale flashes */
add_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_show_product_sale_flash', 10, 2);
add_action( 'woocommerce_before_single_product_summary', 'woocommerce_show_product_sale_flash', 10, 2);
add_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_show_product_loop_sale_flash', 10);
add_action( 'woocommerce_before_single_product_summary', 'woocommerce_show_product_sale_flash', 10);

/* Breadcrumbs */
add_action( 'woocommerce_before_main_content', 'woocommerce_breadcrumb', 20, 0);
Expand All @@ -30,17 +30,16 @@
/* Products Loop */
add_action( 'woocommerce_before_shop_loop', array(&$woocommerce, 'show_messages'), 10 );
add_action( 'woocommerce_before_shop_loop_products', 'woocommerce_product_subcategories' );
add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10, 2);
add_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10, 2);
add_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10, 2);
add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10);
add_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10);
add_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10);

/* Subcategories */
add_action( 'woocommerce_before_subcategory_title', 'woocommerce_subcategory_thumbnail', 10);

/* Before Single Products */
add_action( 'woocommerce_before_single_product', array(&$woocommerce, 'show_messages'), 10 );
add_action( 'woocommerce_before_single_product', 'woocommerce_before_single_product', 10, 2);
add_action( 'woocommerce_before_single_product', 'woocommerce_check_product_visibility', 10, 2);
add_action( 'woocommerce_before_single_product', 'woocommerce_check_product_visibility', 10);

/* Before Single Products Summary Div */
add_action( 'woocommerce_before_single_product_summary', 'woocommerce_show_product_images', 20);
Expand All @@ -51,20 +50,20 @@
add_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20);

/* Product Summary Box */
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10, 2);
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20, 2);
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40, 2);
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_sharing', 50, 2);
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10);
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20);
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40);
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_sharing', 50);

/* After Single Products */
add_action('woocommerce_after_single_product', 'woocommerce_upsell_display');

/* Product Add to cart */
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30, 2 );
add_action( 'woocommerce_simple_add_to_cart', 'woocommerce_simple_add_to_cart', 30, 2 );
add_action( 'woocommerce_grouped_add_to_cart', 'woocommerce_grouped_add_to_cart', 30, 2 );
add_action( 'woocommerce_variable_add_to_cart', 'woocommerce_variable_add_to_cart', 30, 2 );
add_action( 'woocommerce_external_add_to_cart', 'woocommerce_external_add_to_cart', 30, 2 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30);
add_action( 'woocommerce_simple_add_to_cart', 'woocommerce_simple_add_to_cart', 30 );
add_action( 'woocommerce_grouped_add_to_cart', 'woocommerce_grouped_add_to_cart', 30 );
add_action( 'woocommerce_variable_add_to_cart', 'woocommerce_variable_add_to_cart', 30 );
add_action( 'woocommerce_external_add_to_cart', 'woocommerce_external_add_to_cart', 30 );

/* Pagination in loop-shop */
add_action( 'woocommerce_pagination', 'woocommerce_pagination', 10 );
Expand Down

0 comments on commit 35d1d56

Please sign in to comment.