• Resolved Mark

    (@markpfaff)


    I’ve used woocommerce_quantity_input() to insert a quantity input and add to cart button on a page for a particular set of products. For those that are setup with fixed-quantity pricing when you click on the add to cart button it redirects to the product page. Is there a way to insert the dropdown for fixed quantities for a product?

    I’d need to know what property to access to check whether a product has the fixed quantity pricing active and then if there’s a function or chunk of code that would display the dropdown with fixed pricing for that specified product.

    Here’s my code that’s working for the quantity input:

        <form action="<?php echo esc_url( $product->add_to_cart_url() );?>" class="cart <?php echo $lowinv_alert;?>" method="post" enctype="multipart/form-data">
            <td>
                if ($reorder > 0 ){
                    echo woocommerce_quantity_input( array('input_value' => $reorder ), $product, false );
                }else{
                    echo woocommerce_quantity_input( array(), $product, false );
                }
                ?>
    
            </td>
            <td>
                <button type="submit" class="button alt">Add To Cart</button>
            </td>
        </form>

    Any help is much appreciated!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Habibillah

    (@habibillah)

    I don’t understand what is your goal. You may see how to setup custom qty dropdown by following this instruction https://www.ads-software.com/plugins/woocommerce-fixed-quantity/?#faq

    Below is screen how the dropdown price shown

    fixed dropdown price

    Thread Starter Mark

    (@markpfaff)

    Here is a picture of the custom page I’ve created:
    Screenshot of custom product ordering page

    I’ve added an Add to cart button with the code I’ve shown in my first post.

    Instead of showing this:
    quantity input

    I need to show this:
    dropdown quantity

    Is there a way for me to create the dropdown on a custom page?

    • This reply was modified 7 years, 11 months ago by Mark.
    Plugin Author Habibillah

    (@habibillah)

    Thread Starter Mark

    (@markpfaff)

    Thanks Habibillah,

    I was able to make it work with this. It’s just directly in the template for right now but it’s working.

    `//if new order product is setup with fixed quantity create the dropdown
    if (WoofixUtility::isFixedQtyPrice($product->id) !== false) {

    $selected_quantity = !empty($selected_quantity)? $selected_quantity : ”;

    if (method_exists($product,’get_id’)) {
    $productId = $product->get_id();
    } else {
    /**
    * @deprecated
    */
    $productId = $product->id;
    }
    $data = WoofixUtility::isFixedQtyPrice($productId);

    echo ‘<div class=”quantity_select”>’;

    if (!is_cart()) {
    do_action(‘woofix_before_quantity_input’);
    }

    echo ‘<select name=”quantity”‘;
    echo ‘ title=”Product quantity input” ‘;
    echo ‘class=”qty”>’;
    foreach ($data[‘woofix’] as $item): ?>

    <?php
    $woofix_price = $item[‘woofix_price’];
    $woofix_qty = $item[‘woofix_qty’];
    $woofix_disc = $item[‘woofix_disc’] . ‘%’;
    $price = wc_price($woofix_price);
    $total = wc_price($woofix_price * $woofix_qty);

    $woofix_desc = !empty($item[‘woofix_desc’])? $item[‘woofix_desc’] : WOOFIXCONF_QTY_DESC;

    $description = $item[‘woofix_qty’] .’  x ‘. $price.’  = ‘. $total.’ ‘;
    $isselected=($selected_quantity == $woofix_qty)? “selected” : “”;
    echo ‘<option value=”‘. $woofix_qty.'”‘;
    echo ‘data-qty=”‘.$woofix_qty.'”‘;
    echo ‘data-price=”‘.$woofix_price.'”‘.$isselected.’>’;

    echo $description;
    echo ‘</option>’;

    endforeach;
    echo ‘</select>’;`

    • This reply was modified 7 years, 10 months ago by Mark.
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Replace quantity input with dropdown of fixed quantities’ is closed to new replies.