Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Nick Verwymeren

    (@greatwitenorth)

    ok this should work if you paste in your functions.php file. It’s not pretty and I hope to refactor the code to make stuff like this easier in the future, but in the mean time this should work. Also if you want the minimum qty message to appear before the add to cart button, just change the 11 in add_action to a 9:

    add_action( 'woocommerce_after_shop_loop_item', 'wpqu_show_min_on_archive', 11 );
    
    function wpqu_show_min_on_archive(){
    	global $product;
    
    	$settings = get_option( 'ipq_options' );
    	extract( $settings );
    
    	$rule = wcqu_get_applied_rule( $product );
    
    	// Return nothing if APQ is deactivated
    	if ( $rule == 'inactive' or $rule == null ) {
    		return;
    	}
    
    	// 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
    	if ( strlen( $stock ) != 0 and $stock <= 0 ) {
    		$min = wcqu_get_value_from_rule( 'min_oos', $product, $rule );
    		$max = wcqu_get_value_from_rule( 'max_oos', $product, $rule );
    	} 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 ) {
    		$min_pattern = '/\%MIN\%/';
    		$max_pattern = '/\%MAX\%/';
    		$step_pattern = '/\%STEP\%/';
    
    		$ipq_qty_text = preg_replace($min_pattern, $min, $ipq_qty_text);
    		$ipq_qty_text = preg_replace($max_pattern, $max, $ipq_qty_text);
    		$ipq_qty_text = preg_replace($step_pattern, $step, $ipq_qty_text);
    
    		// Output result with optional custom class
    		echo "<div";
    		if ( isset( $ipq_qty_class ) and $ipq_qty_class != '' )
    			echo " class='" . $ipq_qty_class . "'";
    		echo ">";
    		echo $ipq_qty_text;
    		echo "</div>";
    	}
    }
    Plugin Author Nick Verwymeren

    (@greatwitenorth)

    marking this as resolved

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Add Min Qty meta output to shop archive’ is closed to new replies.