Browse Source

Add changes from live version, fixing allowing customer to select more units than in stock

master
Sam Black 3 years ago
parent
commit
d78c17defd
Signed by: samwwwblack GPG Key ID: 0FF0223994EA47D8
  1. 15
      includes/class-wcqu-filters.php
  2. 8
      includes/class-wcqu-product-unit.php
  3. 2
      includes/class-wcqu-units-box.php
  4. 2
      includes/wcqu-functions.php

15
includes/class-wcqu-filters.php

@ -110,13 +110,19 @@ class WC_Quantities_and_Units_Filters {
// Get Value from Rule
$max = wcqu_get_value_from_rule( 'max', $product, $rule );
// Get amount in stock
$stock = $product->get_stock_quantity();
// Return Value
if ( $max == '' or $max == null or (isset($max['max']) and $max['max'] == "")) {
return $default;
} else {
}
elseif ( strlen( $stock ) != 0 && $max < $stock ) {
return $max;
}
else {
return $stock;
}
}
/*
@ -200,9 +206,12 @@ class WC_Quantities_and_Units_Filters {
// Check stock status and if Out try Out of Stock value
if ( $stock <= 0 and isset( $values['min_oos'] ) and $values['max_oos'] != '' ) {
$args['max_value'] = $values['max_oos'];
}
elseif ( strlen( $stock ) != 0 && $values['max_value'] > $stock ) {
$args['max_value'] = $stock;
}
// Otherwise just check normal max
} elseif ($values['max_value'] != '' ) {
elseif ($values['max_value'] != '' ) {
$args['max_value'] = $values['max_value'];
}

8
includes/class-wcqu-product-unit.php

@ -61,7 +61,7 @@ class WC_Quantities_and_Units_Product_Unit {
*/
public function get_price_suffix( $price_display_suffix, $product ) {
// todo make default unit configuarble
if ( $unit = $this->get_unit_for_product( $product->id, apply_filters( 'wciu_default_price_suffix', __( '', 'woocommerce' ) ) ) ) {
if ( $unit = $this->get_unit_for_product( $product->get_id(), apply_filters( 'wciu_default_price_suffix', __( '', 'woocommerce' ) ) ) ) {
$price_display_suffix = "/" . $unit . " " . $price_display_suffix;
}
@ -77,7 +77,7 @@ class WC_Quantities_and_Units_Product_Unit {
* @return string
*/
public function sale_price_from_to( $price, $from, $to, $product ) {
if ( $unit = get_post_meta( $product->id, 'unit', true ) ) {
if ( $unit = get_post_meta( $product->get_id(), 'unit', true ) ) {
$price = '<del>' . ( ( is_numeric( $from ) ) ? wc_price( $from ) : $from ) . '/' . $unit . '</del> <ins>' . ( ( is_numeric( $to ) ) ? wc_price( $to ) : $to ) . '/' . $unit . '</ins>';
}
@ -91,7 +91,7 @@ class WC_Quantities_and_Units_Product_Unit {
* @return string
*/
public function price_html( $html, $product ) {
$unit = get_post_meta( $product->id, 'unit', true );
$unit = get_post_meta( $product->get_id(), 'unit', true );
if ( $unit ) {
return $html . '/' . $unit;
}
@ -109,4 +109,4 @@ class WC_Quantities_and_Units_Product_Unit {
endif;
return new WC_Quantities_and_Units_Product_Unit();
return new WC_Quantities_and_Units_Product_Unit();

2
includes/class-wcqu-units-box.php

@ -111,4 +111,4 @@ if ( ! class_exists( 'WC_Quantities_and_Units_Units_Box' ) ) :
endif;
return new WC_Quantities_and_Units_Units_Box();
return new WC_Quantities_and_Units_Units_Box();

2
includes/wcqu-functions.php

@ -10,7 +10,7 @@
*/
function wcqu_get_applied_rule( $product, $role = null ) {
// Don't apply to Woo Product Bundles
// Don't apply to Woo Product Bundles
if ( $product->product_type == 'woosb' ) {
return;
}

Loading…
Cancel
Save