Categories
Plugins WooCommerce

How to limit min and max quantity for WooCommerce

Min and Max Quantity for WooCommerce plugin allow you to set up limits for the cost of products in orders and in groups and limits for the number of products, product variations, products in orders, and products in the group. You can add products and product variations to the group. An infinite amount of groups.

FEATURES:
✅ Quantity limits for products
✅ Quantity limits for product variations
✅ Quantity limits for products in cart
✅ Cost limits for products in cart

ADDITIONAL FEATURES IN PAID PLUGIN:
✅ Quantity limits for groups of products
✅ Quantity limits for products from categories
✅ Quantity limits for products from specific attributes
✅ Cost limits for groups of products
✅ Cost limits for products from categories
✅ Cost limits for products from specific attributes
✅ Infinite groups of products

Categories
Plugins WooCommerce WordPress WP User Frontend

How to create unique SKU with WP User Frontend custom field.

The unique SKU of the products is not being set when the products are created. To add unique SKU with products, then follow the instructions given below.

1) Add a custom text field with _sku to the product form.

Screenshot:
http://prntscr.com/eb2ext

2) Add the following code inside the theme’s functions.php file.

Note: This is a Developer level doc. If you are unfamiliar with code/templates and resolving potential conflicts, contact me for assistance.
function wpuf_unique_product_sku_notice( $error ) {
    if ( isset( $_POST['_sku'] ) ) {
        global $wpdb;

        $sku = $_POST['_sku'];

        $product_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key='_sku' AND meta_value='%s' LIMIT 1", $sku ) );

        if ( $product_id ) {
            return __( 'SKU is not unique, you must enter unique SKU' );
        }
    }

    return '';
}

add_filter( 'wpuf_update_post_validate', 'wpuf_unique_product_sku_notice' );
add_filter( 'wpuf_add_post_validate', 'wpuf_unique_product_sku_notice' );

3) Now, try to submit a product using the frontend product form. Use an existing SKU related to other product. You will see the following error.

Screenshot:

All done.

Categories
Plugins WooCommerce

How to display quantity input fields next to add to cart buttons.

To display quantity input fields for simple products within your shop archive pages, you can add the following code to your theme’s functions.php file.

Note: This is a Developer level doc. If you are unfamiliar with code/templates and resolving potential conflicts, contact me for assistance.
<?php
/**
 * Code should be placed in your theme functions.php file.
 */

add_filter( 'woocommerce_loop_add_to_cart_link', 'quantity_inputs_for_woocommerce_loop_add_to_cart_link', 10, 2 );
function quantity_inputs_for_woocommerce_loop_add_to_cart_link( $html, $product ) {
    if ( $product && $product->is_type( 'simple' ) && $product->is_purchasable() && $product->is_in_stock() && ! $product->is_sold_individually() ) {
        $html = '<form action="' . esc_url( $product->add_to_cart_url() ) . '" class="cart" method="post" enctype="multipart/form-data">';
        $html .= woocommerce_quantity_input( array(), $product, false );
        $html .= '<button type="submit" class="button alt">' . esc_html( $product->add_to_cart_text() ) . '</button>';
        $html .= '</form>';
    }
    return $html;
}