Free labels for free products, unset price products cannot be added to cart
This commit is contained in:
parent
5cd9629a45
commit
ccb53b7f1b
|
@ -319,6 +319,8 @@ table.wp-list-table .column-thumb img {
|
|||
padding: 2px;
|
||||
border: 1px solid #dfdfdf;
|
||||
vertical-align: middle;
|
||||
width: 42px;
|
||||
height: 42px;
|
||||
}
|
||||
table.wp-list-table span.na {
|
||||
color: #999;
|
||||
|
|
|
@ -346,6 +346,8 @@ table.wp-list-table .column-thumb img {
|
|||
padding: 2px;
|
||||
border: 1px solid #dfdfdf;
|
||||
vertical-align: middle;
|
||||
width: 42px;
|
||||
height: 42px;
|
||||
}
|
||||
table.wp-list-table span.na {
|
||||
color: #999;
|
||||
|
|
|
@ -143,6 +143,14 @@ class woocommerce_cart {
|
|||
|
||||
$found_cart_item_key = self::find_product_in_cart($product_id, $variation_id, $variation);
|
||||
|
||||
$product_data = &new woocommerce_product( $product_id );
|
||||
|
||||
// Price set check
|
||||
if( $product_data->get_price() === '' ) {
|
||||
woocommerce::add_error( __('This product cannot be purchased - the price is not yet announced', 'woothemes') );
|
||||
return false;
|
||||
}
|
||||
|
||||
if (is_numeric($found_cart_item_key)) :
|
||||
|
||||
$quantity = $quantity + self::$cart_contents[$found_cart_item_key]['quantity'];
|
||||
|
@ -152,15 +160,13 @@ class woocommerce_cart {
|
|||
else :
|
||||
|
||||
$cart_item_key = sizeof(self::$cart_contents);
|
||||
|
||||
$data = &new woocommerce_product( $product_id );
|
||||
|
||||
self::$cart_contents[$cart_item_key] = array(
|
||||
'product_id' => $product_id,
|
||||
'variation_id' => $variation_id,
|
||||
'variation' => $variation,
|
||||
'quantity' => $quantity,
|
||||
'data' => $data
|
||||
'data' => $product_data
|
||||
);
|
||||
|
||||
endif;
|
||||
|
|
|
@ -48,7 +48,7 @@ class woocommerce_product {
|
|||
// Define the data we're going to load: Key => Default value
|
||||
$load_data = array(
|
||||
'sku' => $this->id,
|
||||
'price' => 0,
|
||||
'price' => '',
|
||||
'visibility' => 'hidden',
|
||||
'stock' => 0,
|
||||
'stock_status' => 'instock',
|
||||
|
@ -65,7 +65,7 @@ class woocommerce_product {
|
|||
|
||||
// Load the data from the custom fields
|
||||
foreach ($load_data as $key => $default) :
|
||||
if (isset($product_custom_fields[$key][0]) && !empty($product_custom_fields[$key][0])) :
|
||||
if (isset($product_custom_fields[$key][0]) && $product_custom_fields[$key][0]!=='') :
|
||||
$this->$key = $product_custom_fields[$key][0];
|
||||
else :
|
||||
$this->$key = $default;
|
||||
|
@ -401,7 +401,7 @@ class woocommerce_product {
|
|||
|
||||
else :
|
||||
|
||||
if ( $this->sale_price==$this->price ) :
|
||||
if ( $this->sale_price && $this->sale_price==$this->price ) :
|
||||
return true;
|
||||
endif;
|
||||
|
||||
|
@ -494,6 +494,10 @@ class woocommerce_product {
|
|||
else :
|
||||
$price .= woocommerce_price($this->get_price());
|
||||
endif;
|
||||
elseif ($this->price === '' ) :
|
||||
return false;
|
||||
elseif ($this->price === '0' ) :
|
||||
$price = __('Free!', 'woothemes');
|
||||
endif;
|
||||
endif;
|
||||
return $price;
|
||||
|
|
|
@ -75,7 +75,11 @@ if (!function_exists('woocommerce_get_sidebar')) {
|
|||
* Products Loop
|
||||
**/
|
||||
if (!function_exists('woocommerce_template_loop_add_to_cart')) {
|
||||
function woocommerce_template_loop_add_to_cart( $post, $_product ) {
|
||||
function woocommerce_template_loop_add_to_cart( $post, $_product ) {
|
||||
|
||||
// No price set - so no button
|
||||
if( $_product->get_price() === '') return;
|
||||
|
||||
?><a href="<?php echo $_product->add_to_cart_url(); ?>" rel="<?php echo $_product->id; ?>" class="button add_to_cart_button product_type_<?php echo $_product->product_type; ?>"><?php _e('Add to cart', 'woothemes'); ?></a><?php
|
||||
}
|
||||
}
|
||||
|
@ -240,6 +244,9 @@ if (!function_exists('woocommerce_simple_add_to_cart')) {
|
|||
function woocommerce_simple_add_to_cart() {
|
||||
|
||||
global $_product; $availability = $_product->get_availability();
|
||||
|
||||
// No price set - so no button
|
||||
if( $_product->get_price() === '') return;
|
||||
|
||||
if ($availability['availability']) : ?><p class="stock <?php echo $availability['class'] ?>"><?php echo $availability['availability']; ?></p><?php endif;
|
||||
|
||||
|
@ -263,7 +270,10 @@ if (!function_exists('woocommerce_downloadable_add_to_cart')) {
|
|||
function woocommerce_downloadable_add_to_cart() {
|
||||
|
||||
global $_product; $availability = $_product->get_availability();
|
||||
|
||||
|
||||
// No price set - so no button
|
||||
if( $_product->get_price() === '') return;
|
||||
|
||||
if ($availability['availability']) : ?><p class="stock <?php echo $availability['class'] ?>"><?php echo $availability['availability']; ?></p><?php endif;
|
||||
|
||||
?>
|
||||
|
|
Loading…
Reference in New Issue