Fix JS enqueue. Closes #1365.
This commit is contained in:
parent
d5163c5638
commit
402799c0eb
|
@ -154,6 +154,8 @@ Yes you can! Join in on our [GitHub repository](http://github.com/woothemes/wooc
|
|||
* Fix - Missing grouped product cart buttons
|
||||
* Fix - Notice in invoice template with number_format
|
||||
* Fix - Made variation get_image() return instead of echo
|
||||
* Fix - Remove is_product check so variation JS can register itself for use. Same for the single product JS
|
||||
* Fix - Above fix also fixes single product shortcodes
|
||||
|
||||
= 1.6.3 - 10/08/2012 =
|
||||
* Feature - Option to register using the email address as the username instead of entering a username
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
/**
|
||||
* Shortcodes init
|
||||
*
|
||||
*
|
||||
* Init main shortcodes, and add a few others such as recent products.
|
||||
*
|
||||
* @package WooCommerce
|
||||
|
@ -20,9 +20,9 @@ include_once('shortcode-thankyou.php');
|
|||
**/
|
||||
function woocommerce_product_category($atts){
|
||||
global $woocommerce_loop;
|
||||
|
||||
|
||||
if (empty($atts)) return;
|
||||
|
||||
|
||||
extract(shortcode_atts(array(
|
||||
'per_page' => '12',
|
||||
'columns' => '4',
|
||||
|
@ -30,9 +30,9 @@ function woocommerce_product_category($atts){
|
|||
'order' => 'asc',
|
||||
'category' => ''
|
||||
), $atts));
|
||||
|
||||
|
||||
if ( ! $category ) return;
|
||||
|
||||
|
||||
$args = array(
|
||||
'post_type' => 'product',
|
||||
'post_status' => 'publish',
|
||||
|
@ -56,36 +56,36 @@ function woocommerce_product_category($atts){
|
|||
)
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
ob_start();
|
||||
|
||||
|
||||
$products = new WP_Query( $args );
|
||||
|
||||
|
||||
$woocommerce_loop['columns'] = $columns;
|
||||
|
||||
if ( $products->have_posts() ) : ?>
|
||||
|
||||
|
||||
<ul class="products">
|
||||
|
||||
|
||||
<?php while ( $products->have_posts() ) : $products->the_post(); ?>
|
||||
|
||||
|
||||
<?php woocommerce_get_template_part( 'content', 'product' ); ?>
|
||||
|
||||
|
||||
<?php endwhile; // end of the loop. ?>
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
<?php endif;
|
||||
|
||||
<?php endif;
|
||||
|
||||
wp_reset_query();
|
||||
|
||||
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
/**
|
||||
* List all (or limited) product categories
|
||||
**/
|
||||
function woocommerce_product_categories( $atts ) {
|
||||
function woocommerce_product_categories( $atts ) {
|
||||
global $woocommerce_loop;
|
||||
|
||||
extract( shortcode_atts( array (
|
||||
|
@ -104,7 +104,7 @@ function woocommerce_product_categories( $atts ) {
|
|||
}
|
||||
|
||||
$hide_empty = ( $hide_empty == true || $hide_empty == 1 ) ? 1 : 0;
|
||||
|
||||
|
||||
$args = array(
|
||||
'number' => $number,
|
||||
'orderby' => $orderby,
|
||||
|
@ -112,34 +112,34 @@ function woocommerce_product_categories( $atts ) {
|
|||
'hide_empty' => $hide_empty,
|
||||
'include' => $ids
|
||||
);
|
||||
|
||||
|
||||
$product_categories = get_terms( 'product_cat', $args );
|
||||
|
||||
$woocommerce_loop['columns'] = $columns;
|
||||
|
||||
|
||||
ob_start();
|
||||
|
||||
|
||||
// Reset loop/columns globals when starting a new loop
|
||||
$woocommerce_loop['loop'] = $woocommerce_loop['column'] = '';
|
||||
|
||||
|
||||
if ( $product_categories ) {
|
||||
|
||||
|
||||
echo '<ul class="products">';
|
||||
|
||||
|
||||
foreach ( $product_categories as $category ) {
|
||||
|
||||
|
||||
woocommerce_get_template( 'content-product_cat.php', array(
|
||||
'category' => $category
|
||||
) );
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
echo '</ul>';
|
||||
|
||||
}
|
||||
|
||||
wp_reset_query();
|
||||
|
||||
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
|
@ -147,16 +147,16 @@ function woocommerce_product_categories( $atts ) {
|
|||
* Recent Products shortcode
|
||||
**/
|
||||
function woocommerce_recent_products( $atts ) {
|
||||
|
||||
|
||||
global $woocommerce_loop;
|
||||
|
||||
|
||||
extract(shortcode_atts(array(
|
||||
'per_page' => '12',
|
||||
'columns' => '4',
|
||||
'orderby' => 'date',
|
||||
'order' => 'desc'
|
||||
), $atts));
|
||||
|
||||
|
||||
$args = array(
|
||||
'post_type' => 'product',
|
||||
'post_status' => 'publish',
|
||||
|
@ -172,29 +172,29 @@ function woocommerce_recent_products( $atts ) {
|
|||
)
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
ob_start();
|
||||
|
||||
$products = new WP_Query( $args );
|
||||
|
||||
|
||||
$woocommerce_loop['columns'] = $columns;
|
||||
|
||||
if ( $products->have_posts() ) : ?>
|
||||
|
||||
|
||||
<ul class="products">
|
||||
|
||||
|
||||
<?php while ( $products->have_posts() ) : $products->the_post(); ?>
|
||||
|
||||
|
||||
<?php woocommerce_get_template_part( 'content', 'product' ); ?>
|
||||
|
||||
|
||||
<?php endwhile; // end of the loop. ?>
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
<?php endif;
|
||||
|
||||
<?php endif;
|
||||
|
||||
wp_reset_query();
|
||||
|
||||
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
|
@ -203,15 +203,15 @@ function woocommerce_recent_products( $atts ) {
|
|||
**/
|
||||
function woocommerce_products($atts){
|
||||
global $woocommerce_loop;
|
||||
|
||||
|
||||
if (empty($atts)) return;
|
||||
|
||||
|
||||
extract(shortcode_atts(array(
|
||||
'columns' => '4',
|
||||
'orderby' => 'title',
|
||||
'order' => 'asc'
|
||||
), $atts));
|
||||
|
||||
|
||||
$args = array(
|
||||
'post_type' => 'product',
|
||||
'post_status' => 'publish',
|
||||
|
@ -227,7 +227,7 @@ function woocommerce_products($atts){
|
|||
)
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
if(isset($atts['skus'])){
|
||||
$skus = explode(',', $atts['skus']);
|
||||
$skus = array_map('trim', $skus);
|
||||
|
@ -237,32 +237,32 @@ function woocommerce_products($atts){
|
|||
'compare' => 'IN'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
if(isset($atts['ids'])){
|
||||
$ids = explode(',', $atts['ids']);
|
||||
$ids = array_map('trim', $ids);
|
||||
$args['post__in'] = $ids;
|
||||
}
|
||||
|
||||
|
||||
ob_start();
|
||||
|
||||
$products = new WP_Query( $args );
|
||||
|
||||
|
||||
$woocommerce_loop['columns'] = $columns;
|
||||
|
||||
if ( $products->have_posts() ) : ?>
|
||||
|
||||
|
||||
<ul class="products">
|
||||
|
||||
|
||||
<?php while ( $products->have_posts() ) : $products->the_post(); ?>
|
||||
|
||||
|
||||
<?php woocommerce_get_template_part( 'content', 'product' ); ?>
|
||||
|
||||
|
||||
<?php endwhile; // end of the loop. ?>
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
<?php endif;
|
||||
|
||||
<?php endif;
|
||||
|
||||
wp_reset_query();
|
||||
|
||||
|
@ -274,7 +274,7 @@ function woocommerce_products($atts){
|
|||
**/
|
||||
function woocommerce_product($atts){
|
||||
if (empty($atts)) return;
|
||||
|
||||
|
||||
$args = array(
|
||||
'post_type' => 'product',
|
||||
'posts_per_page' => 1,
|
||||
|
@ -288,7 +288,7 @@ function woocommerce_product($atts){
|
|||
)
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
if(isset($atts['sku'])){
|
||||
$args['meta_query'][] = array(
|
||||
'key' => '_sku',
|
||||
|
@ -296,32 +296,32 @@ function woocommerce_product($atts){
|
|||
'compare' => '='
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
if(isset($atts['id'])){
|
||||
$args['p'] = $atts['id'];
|
||||
}
|
||||
|
||||
|
||||
ob_start();
|
||||
|
||||
$products = new WP_Query( $args );
|
||||
|
||||
if ( $products->have_posts() ) : ?>
|
||||
|
||||
|
||||
<ul class="products">
|
||||
|
||||
|
||||
<?php while ( $products->have_posts() ) : $products->the_post(); ?>
|
||||
|
||||
|
||||
<?php woocommerce_get_template_part( 'content', 'product' ); ?>
|
||||
|
||||
|
||||
<?php endwhile; // end of the loop. ?>
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
<?php endif;
|
||||
|
||||
<?php endif;
|
||||
|
||||
wp_reset_query();
|
||||
|
||||
return ob_get_clean();
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
|
||||
|
@ -330,11 +330,11 @@ function woocommerce_product($atts){
|
|||
**/
|
||||
function woocommerce_product_add_to_cart($atts){
|
||||
if (empty($atts)) return;
|
||||
|
||||
|
||||
global $wpdb, $woocommerce;
|
||||
|
||||
|
||||
if (!isset($atts['style'])) $atts['style'] = 'border:4px solid #ccc; padding: 12px;';
|
||||
|
||||
|
||||
if ($atts['id']) :
|
||||
$product_data = get_post( $atts['id'] );
|
||||
elseif ($atts['sku']) :
|
||||
|
@ -343,56 +343,56 @@ function woocommerce_product_add_to_cart($atts){
|
|||
else :
|
||||
return;
|
||||
endif;
|
||||
|
||||
|
||||
if ($product_data->post_type=='product') {
|
||||
|
||||
|
||||
$product = $woocommerce->setup_product_data( $product_data );
|
||||
|
||||
|
||||
ob_start();
|
||||
?>
|
||||
<p class="product" style="<?php echo $atts['style']; ?>">
|
||||
|
||||
|
||||
<?php echo $product->get_price_html(); ?>
|
||||
|
||||
|
||||
<?php woocommerce_template_loop_add_to_cart(); ?>
|
||||
|
||||
</p><?php
|
||||
|
||||
return ob_get_clean();
|
||||
|
||||
|
||||
</p><?php
|
||||
|
||||
return ob_get_clean();
|
||||
|
||||
} elseif ($product_data->post_type=='product_variation') {
|
||||
|
||||
|
||||
$product = new WC_Product( $product_data->post_parent );
|
||||
|
||||
|
||||
$GLOBALS['product'] = $product;
|
||||
|
||||
|
||||
$variation = new WC_Product_Variation( $product_data->ID );
|
||||
|
||||
|
||||
ob_start();
|
||||
?>
|
||||
<p class="product product-variation" style="<?php echo $atts['style']; ?>">
|
||||
|
||||
|
||||
<?php echo $product->get_price_html(); ?>
|
||||
|
||||
|
||||
<?php
|
||||
|
||||
|
||||
$link = $product->add_to_cart_url();
|
||||
|
||||
|
||||
$label = apply_filters('add_to_cart_text', __('Add to cart', 'woocommerce'));
|
||||
|
||||
|
||||
$link = add_query_arg( 'variation_id', $variation->variation_id, $link );
|
||||
|
||||
|
||||
foreach ($variation->variation_data as $key => $data) {
|
||||
if ($data) $link = add_query_arg( $key, $data, $link );
|
||||
}
|
||||
|
||||
|
||||
printf('<a href="%s" rel="nofollow" data-product_id="%s" class="button add_to_cart_button product_type_%s">%s</a>', esc_url( $link ), $product->id, $product->product_type, $label);
|
||||
|
||||
|
||||
?>
|
||||
|
||||
</p><?php
|
||||
|
||||
return ob_get_clean();
|
||||
|
||||
</p><?php
|
||||
|
||||
return ob_get_clean();
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -403,9 +403,9 @@ function woocommerce_product_add_to_cart($atts){
|
|||
**/
|
||||
function woocommerce_product_add_to_cart_url( $atts ){
|
||||
if (empty($atts)) return;
|
||||
|
||||
|
||||
global $wpdb;
|
||||
|
||||
|
||||
if ($atts['id']) :
|
||||
$product_data = get_post( $atts['id'] );
|
||||
elseif ($atts['sku']) :
|
||||
|
@ -414,11 +414,11 @@ function woocommerce_product_add_to_cart_url( $atts ){
|
|||
else :
|
||||
return;
|
||||
endif;
|
||||
|
||||
|
||||
if ($product_data->post_type!=='product') return;
|
||||
|
||||
$_product = new WC_Product( $product_data->ID );
|
||||
|
||||
|
||||
$_product = new WC_Product( $product_data->ID );
|
||||
|
||||
return esc_url( $_product->add_to_cart_url() );
|
||||
}
|
||||
|
||||
|
@ -427,16 +427,16 @@ function woocommerce_product_add_to_cart_url( $atts ){
|
|||
* Output featured products
|
||||
**/
|
||||
function woocommerce_featured_products( $atts ) {
|
||||
|
||||
|
||||
global $woocommerce_loop;
|
||||
|
||||
|
||||
extract(shortcode_atts(array(
|
||||
'per_page' => '12',
|
||||
'columns' => '4',
|
||||
'orderby' => 'date',
|
||||
'order' => 'desc'
|
||||
), $atts));
|
||||
|
||||
|
||||
$args = array(
|
||||
'post_type' => 'product',
|
||||
'post_status' => 'publish',
|
||||
|
@ -460,25 +460,25 @@ function woocommerce_featured_products( $atts ) {
|
|||
ob_start();
|
||||
|
||||
$products = new WP_Query( $args );
|
||||
|
||||
|
||||
$woocommerce_loop['columns'] = $columns;
|
||||
|
||||
if ( $products->have_posts() ) : ?>
|
||||
|
||||
|
||||
<ul class="products">
|
||||
|
||||
|
||||
<?php while ( $products->have_posts() ) : $products->the_post(); ?>
|
||||
|
||||
|
||||
<?php woocommerce_get_template_part( 'content', 'product' ); ?>
|
||||
|
||||
|
||||
<?php endwhile; // end of the loop. ?>
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
<?php endif;
|
||||
|
||||
<?php endif;
|
||||
|
||||
wp_reset_query();
|
||||
|
||||
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
|
@ -487,9 +487,9 @@ function woocommerce_featured_products( $atts ) {
|
|||
**/
|
||||
function woocommerce_product_page_shortcode( $atts ) {
|
||||
if (empty($atts)) return;
|
||||
|
||||
|
||||
if (!$atts['id'] && !$atts['sku']) return;
|
||||
|
||||
|
||||
$args = array(
|
||||
'posts_per_page' => 1,
|
||||
'post_type' => 'product',
|
||||
|
@ -509,34 +509,34 @@ function woocommerce_product_page_shortcode( $atts ) {
|
|||
if(isset($atts['id'])){
|
||||
$args['p'] = $atts['id'];
|
||||
}
|
||||
|
||||
|
||||
$single_product = new WP_Query( $args );
|
||||
|
||||
ob_start();
|
||||
|
||||
while ( $single_product->have_posts() ) : $single_product->the_post(); ?>
|
||||
|
||||
while ( $single_product->have_posts() ) : $single_product->the_post(); wp_enqueue_script( 'wc-single-product' ); ?>
|
||||
|
||||
<div class="single-product">
|
||||
|
||||
|
||||
<?php woocommerce_get_template_part( 'content', 'single-product' ); ?>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<?php endwhile; // end of the loop.
|
||||
|
||||
wp_reset_query();
|
||||
|
||||
|
||||
return ob_get_clean();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show messages
|
||||
**/
|
||||
function woocommerce_messages_shortcode() {
|
||||
ob_start();
|
||||
|
||||
|
||||
woocommerce_show_messages();
|
||||
|
||||
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
|
|
|
@ -953,6 +953,8 @@ class Woocommerce {
|
|||
* Register/queue frontend scripts
|
||||
*/
|
||||
function frontend_scripts() {
|
||||
global $post;
|
||||
|
||||
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
|
||||
$lightbox_en = get_option('woocommerce_enable_lightbox') == 'yes' ? true : false;
|
||||
$chosen_en = get_option( 'woocommerce_enable_chosen' ) == 'yes' ? true : false;
|
||||
|
@ -962,9 +964,8 @@ class Woocommerce {
|
|||
wp_register_script( 'chosen', $this->plugin_url() . '/assets/js/chosen/chosen.jquery' . $suffix . '.js', array( 'jquery' ), '1.6', true );
|
||||
wp_register_script( 'jquery-ui', $this->plugin_url() . '/assets/js/jquery-ui' . $suffix . '.js', array( 'jquery' ), '1.6', true );
|
||||
wp_register_script( 'jquery-plugins', $this->plugin_url() . '/assets/js/jquery-plugins' . $suffix . '.js', array( 'jquery' ), '1.6', true );
|
||||
|
||||
if ( is_product() )
|
||||
wp_register_script( 'wc-add-to-cart-variation', $frontend_script_path . 'add-to-cart-variation' . $suffix . '.js', array( 'jquery' ), '1.6', true );
|
||||
wp_register_script( 'wc-add-to-cart-variation', $frontend_script_path . 'add-to-cart-variation' . $suffix . '.js', array( 'jquery' ), '1.6', true );
|
||||
wp_register_script( 'wc-single-product', $frontend_script_path . 'single-product' . $suffix . '.js', array( 'jquery' ), '1.6', true );
|
||||
|
||||
// Queue frontend scripts conditionally
|
||||
if ( get_option( 'woocommerce_enable_ajax_add_to_cart' ) == 'yes' )
|
||||
|
@ -977,9 +978,9 @@ class Woocommerce {
|
|||
wp_enqueue_script( 'wc-checkout', $frontend_script_path . 'checkout' . $suffix . '.js', array( 'jquery' ), '1.6', true );
|
||||
|
||||
if ( is_product() )
|
||||
wp_enqueue_script( 'wc-single-product', $frontend_script_path . 'single-product' . $suffix . '.js', array( 'jquery' ), '1.6', true );
|
||||
wp_enqueue_script( 'wc-single-product' );
|
||||
|
||||
if ( $lightbox_en && is_product() ) {
|
||||
if ( $lightbox_en && ( is_product() || ( ! empty( $post->post_content ) && strstr( $post->post_content, '[product_page' ) ) ) ) {
|
||||
wp_enqueue_script( 'fancybox', $this->plugin_url() . '/assets/js/fancybox/fancybox' . $suffix . '.js', array( 'jquery' ), '1.6', true );
|
||||
wp_enqueue_style( 'woocommerce_fancybox_styles', $this->plugin_url() . '/assets/css/fancybox.css' );
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue