Skip to content

Commit

Permalink
Incluse pull request fino alla greatwitenorth#11
Browse files Browse the repository at this point in the history
  • Loading branch information
gine committed Aug 24, 2018
1 parent a940eef commit 071f08f
Show file tree
Hide file tree
Showing 9 changed files with 326 additions and 309 deletions.
76 changes: 39 additions & 37 deletions includes/class-wcqu-actions.php
Original file line number Diff line number Diff line change
@@ -1,89 +1,91 @@
<?php
<?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly

if ( ! class_exists( 'WC_Quantities_and_Units_Actions' ) ) :

class WC_Quantities_and_Units_Actions {

public function __construct() {

// Conditionally add quantity note to product page
$settings = get_option( 'ipq_options' );

if ( isset( $settings['ipq_show_qty_note'] ) and $settings['ipq_show_qty_note'] == 'on' ) {
add_action( 'init', array( $this, 'apply_product_notification' ) );
}

// Add quantity message shortcode
add_shortcode('wpbo_quantity_message', array( $this, 'display_minimum_quantity_note' ));

}

/*
* Adds minimum product notification at correct action level
* Adds minimum product notification at correct action level
* if users applies message
*
* @access public
* @access public
* @return void
*/
*/
public function apply_product_notification() {

$settings = get_option( 'ipq_options' );
extract( $settings );

if ( isset( $ipq_show_qty_note ) and $ipq_show_qty_note == 'on' ) {

// Get add_to_cart action priority
global $wp_filter;
$action_to_check = 'woocommerce_single_product_summary';
$target_function = 'woocommerce_template_single_add_to_cart';
$cart_priority = has_filter( $action_to_check, $target_function );

// Set the priory level based on add to cart
if ( $cart_priority == null ) {
$priority = 30;

} elseif ( isset( $ipq_show_qty_note_pos ) and $ipq_show_qty_note_pos == 'below' ) {
$priority = $cart_priority + 1;

} else {
$priority = $cart_priority - 1;
}

add_action( 'woocommerce_single_product_summary', array( $this, 'display_minimum_quantity_note' ), $priority );

}
add_action( 'woocommerce_after_shop_loop_item_title', array( $this, 'display_minimum_quantity_note' ), 10, 2);
}
}

/*
* Print the minimum quantity note based on user specs
*
* @access public
* @access public
* @return void
*/
*/
public function display_minimum_quantity_note() {

global $product;


/*I'm commenting this out so i can show minimum qty on archive.
if ( !is_product() ) {
return;
}

if( $product->product_type == 'grouped' )
*/

if( $product->is_type('grouped') )
return;

$settings = get_option( 'ipq_options' );
extract( $settings );
// Get minimum value for product

// Get minimum value for product
$rule = wcqu_get_applied_rule( $product );

// Return nothing if APQ is deactivated
if ( $rule == 'inactive' or $rule == null ) {
return;
return;
}
// Check if the product is out of stock

// Check if the product is out of stock
$stock = $product->get_stock_quantity();

// Check if the product is under stock management and out of stock
Expand All @@ -93,33 +95,33 @@ public function display_minimum_quantity_note() {
} else {
$min = wcqu_get_value_from_rule( 'min', $product, $rule );
$max = wcqu_get_value_from_rule( 'max', $product, $rule );
}
}

$step = wcqu_get_value_from_rule( 'step', $product, $rule );

// If sitewide rule is applied, convert return arrays to values
if ( $rule == 'sitewide' and strlen( $stock ) != 0 and $stock <= 0 ) {
if ( is_array( $min ) )
$min = $min['min_oos'];

if ( is_array( $max ) )
$max = $max['max_oos'];

if ( is_array( $step ) ) {
$step = $step['step'];
}
} else if ( $rule == 'sitewide' ) {
if ( is_array( $min ) )
$min = $min['min'];

if ( is_array( $max ) )
$max = $max['max'];

if ( is_array( $step ) ) {
$step = $step['step'];
}
}

// If the text is set, update and print the output
if ( isset( $ipq_qty_text ) ) {
$min_pattern = '/\%MIN\%/';
Expand All @@ -134,7 +136,7 @@ public function display_minimum_quantity_note() {
echo "<span";
if ( isset( $ipq_qty_class ) and $ipq_qty_class != '' )
echo " class='" . $ipq_qty_class . "'";
echo ">";
echo ">";
echo $ipq_qty_text;
echo "</span>";
}
Expand Down
10 changes: 5 additions & 5 deletions includes/class-wcqu-filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function __construct() {
*/
public function woocommerce_loop_add_to_cart_args( $args, $product ) {
// Return Defaults if it isn't a simple product
if( $product->product_type != 'simple' ) {
if( ! $product->is_type( 'simple' ) ) {
return $args;
}

Expand Down Expand Up @@ -68,7 +68,7 @@ public function woocommerce_loop_add_to_cart_args( $args, $product ) {
public function input_min_value( $default, $product ) {

// Return Defaults if it isn't a simple product
if( $product->product_type != 'simple' ) {
if( ! $product->is_type( 'simple' ) ) {
return $default;
}

Expand Down Expand Up @@ -97,7 +97,7 @@ public function input_min_value( $default, $product ) {
public function input_max_value( $default, $product ) {

// Return Defaults if it isn't a simple product
if( $product->product_type != 'simple' ) {
if( ! $product->is_type( 'simple' ) ) {
return $default;
}

Expand Down Expand Up @@ -127,7 +127,7 @@ public function input_max_value( $default, $product ) {
public function input_step_value( $default, $product ) {

// Return Defaults if it isn't a simple product
if( $product->product_type != 'simple' ) {
if( ! $product->is_type( 'simple' ) ) {
return $default;
}

Expand Down Expand Up @@ -159,7 +159,7 @@ public function input_set_all_values( $args, $product ) {
// Return Defaults if it isn't a simple product
/* Commented out to allow for grouped and variable products
* on their product pages
if( $product->product_type != 'simple' ) {
if( ! $product->is_type( 'simple' ) ) {
return $args;
}
*/
Expand Down
Loading

0 comments on commit 071f08f

Please sign in to comment.