Added support to exclude images from product page
This commit is contained in:
parent
f8e006069e
commit
b5297200b9
|
@ -32,6 +32,7 @@ function install_woocommerce() {
|
||||||
woocommerce_create_pages();
|
woocommerce_create_pages();
|
||||||
woocommerce_tables_install();
|
woocommerce_tables_install();
|
||||||
woocommerce_default_taxonomies();
|
woocommerce_default_taxonomies();
|
||||||
|
woocommerce_populate_custom_fields();
|
||||||
|
|
||||||
// Update version
|
// Update version
|
||||||
update_option( "woocommerce_db_version", WOOCOMMERCE_VERSION );
|
update_option( "woocommerce_db_version", WOOCOMMERCE_VERSION );
|
||||||
|
@ -54,6 +55,24 @@ function install_woocommerce_redirect() {
|
||||||
endif;
|
endif;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add required post meta so queries work
|
||||||
|
*/
|
||||||
|
function woocommerce_populate_custom_fields() {
|
||||||
|
|
||||||
|
// Attachment exclusion
|
||||||
|
$args = array(
|
||||||
|
'post_type' => 'attachment',
|
||||||
|
'numberposts' => -1,
|
||||||
|
'post_status' => null,
|
||||||
|
'fields' => 'ids'
|
||||||
|
);
|
||||||
|
$attachments = get_posts($args);
|
||||||
|
if ($attachments) foreach ($attachments as $id) :
|
||||||
|
add_post_meta($id, '_woocommerce_exclude_image', 0);
|
||||||
|
endforeach;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default options
|
* Default options
|
||||||
|
|
|
@ -335,6 +335,47 @@ function woocommerce_products_by_type() {
|
||||||
endif;
|
endif;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add functionality to the image uploader on product pages to exlcude an image
|
||||||
|
**/
|
||||||
|
add_filter('attachment_fields_to_edit', 'woocommerce_exclude_image_from_product_page_field', 1, 2);
|
||||||
|
add_filter('attachment_fields_to_save', 'woocommerce_exclude_image_from_product_page_field_save', 1, 2);
|
||||||
|
|
||||||
|
function woocommerce_exclude_image_from_product_page_field( $fields, $object ) {
|
||||||
|
|
||||||
|
if (!$object->post_parent) return;
|
||||||
|
|
||||||
|
$parent = get_post( $object->post_parent );
|
||||||
|
|
||||||
|
if ($parent->post_type!=='product') return;
|
||||||
|
|
||||||
|
$exclude_image = (int) get_post_meta($object->ID, '_woocommerce_exclude_image', true);
|
||||||
|
|
||||||
|
$label = __('Exclude image', 'woothemes');
|
||||||
|
|
||||||
|
$html = '<input type="checkbox" '.checked($exclude_image, 1, false).' name="attachments['.$object->ID.'][woocommerce_exclude_image]" id="attachments['.$object->ID.'][woocommerce_exclude_image" />';
|
||||||
|
|
||||||
|
$fields['woocommerce_exclude_image'] = array(
|
||||||
|
'label' => $label,
|
||||||
|
'input' => 'html',
|
||||||
|
'html' => $html,
|
||||||
|
'value' => '',
|
||||||
|
'helps' => __('Enabling this option will hide it from the product page image gallery.', 'woothemes')
|
||||||
|
);
|
||||||
|
|
||||||
|
return $fields;
|
||||||
|
}
|
||||||
|
|
||||||
|
function woocommerce_exclude_image_from_product_page_field_save( $post, $attachment ) {
|
||||||
|
|
||||||
|
if (isset($_REQUEST['attachments'][$post['ID']]['woocommerce_exclude_image']))
|
||||||
|
update_post_meta($post['ID'], '_woocommerce_exclude_image', 1);
|
||||||
|
else
|
||||||
|
update_post_meta($post['ID'], '_woocommerce_exclude_image', 0);
|
||||||
|
|
||||||
|
return $post;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -130,7 +130,7 @@ $woocommerce_settings['pages'] = apply_filters('woocommerce_page_settings', arra
|
||||||
|
|
||||||
array(
|
array(
|
||||||
'name' => __( 'Shop Base Page', 'woothemes' ),
|
'name' => __( 'Shop Base Page', 'woothemes' ),
|
||||||
'desc' => sprintf( __( 'This sets the base page of your shop. IMPORTANT: You must %1$sre-save your permalinks%2$s for this change to take effect.', 'woothemes' ), '<a target="_blank" href="options-permalink.php">', '</a>' ),
|
'desc' => sprintf( __( 'This sets the base page of your shop.', 'woothemes' ), '<a target="_blank" href="options-permalink.php">', '</a>' ),
|
||||||
'id' => 'woocommerce_shop_page_id',
|
'id' => 'woocommerce_shop_page_id',
|
||||||
'css' => 'min-width:175px;',
|
'css' => 'min-width:175px;',
|
||||||
'type' => 'single_select_page',
|
'type' => 'single_select_page',
|
||||||
|
|
|
@ -69,6 +69,8 @@ The manual installation involves downloading the plugin and uploading it to your
|
||||||
* unique sku check only checks products
|
* unique sku check only checks products
|
||||||
* More security audit tweaks thanks to Mark Jaquith
|
* More security audit tweaks thanks to Mark Jaquith
|
||||||
* cart totals update when adding cross-sells to cart
|
* cart totals update when adding cross-sells to cart
|
||||||
|
* Removed the 'resave permalinks message' due to it being done automatically
|
||||||
|
* Added support to exclude images from product page
|
||||||
|
|
||||||
= 1.0.1 - 29/09/2011 =
|
= 1.0.1 - 29/09/2011 =
|
||||||
* Fixed notices on product page
|
* Fixed notices on product page
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
/*
|
/*
|
||||||
Plugin Name: WooCommerce
|
Plugin Name: WooCommerce
|
||||||
Plugin URI: http://woocommerce.com
|
Plugin URI: http://www.woothemes.com/woocommerce/
|
||||||
Description: An eCommerce plugin for wordpress.
|
Description: An eCommerce plugin for wordpress.
|
||||||
Version: 1.0.2
|
Version: 1.0.2
|
||||||
Author: WooThemes
|
Author: WooThemes
|
||||||
|
|
|
@ -136,15 +136,26 @@ if (!function_exists('woocommerce_show_product_thumbnails')) {
|
||||||
|
|
||||||
$thumb_id = get_post_thumbnail_id();
|
$thumb_id = get_post_thumbnail_id();
|
||||||
$small_thumbnail_size = apply_filters('single_product_small_thumbnail_size', 'shop_thumbnail');
|
$small_thumbnail_size = apply_filters('single_product_small_thumbnail_size', 'shop_thumbnail');
|
||||||
$args = array( 'post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null, 'post_parent' => $post->ID );
|
$args = array(
|
||||||
|
'post_type' => 'attachment',
|
||||||
|
'numberposts' => -1,
|
||||||
|
'post_status' => null,
|
||||||
|
'post_parent' => $post->ID,
|
||||||
|
'post__not_in' => array($thumb_id),
|
||||||
|
'meta_query' => array(
|
||||||
|
array(
|
||||||
|
'key' => '_woocommerce_exclude_image',
|
||||||
|
'value' => '1',
|
||||||
|
'compare' => '!='
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
$attachments = get_posts($args);
|
$attachments = get_posts($args);
|
||||||
if ($attachments) :
|
if ($attachments) :
|
||||||
$loop = 0;
|
$loop = 0;
|
||||||
$columns = 3;
|
$columns = 3;
|
||||||
foreach ( $attachments as $attachment ) :
|
foreach ( $attachments as $attachment ) :
|
||||||
|
|
||||||
if ($thumb_id==$attachment->ID) continue;
|
|
||||||
|
|
||||||
$loop++;
|
$loop++;
|
||||||
|
|
||||||
$_post = & get_post( $attachment->ID );
|
$_post = & get_post( $attachment->ID );
|
||||||
|
|
Loading…
Reference in New Issue