1

I'm using wp-crowdfunding extension, and i'm overriding a file called "fund-campaign-btn.php".

what it does : display a field and a button, so you can type your price and click on the button to send your price to the checkout page of woocommerce.

In my case I changed it a bit, instead of a blank field I made a list of prices, so the user click on the price he want, then click on the button. The list work but i can't figured out why when i click on the button, it send '0' to my checkout.

Here the original code :

 <form enctype="multipart/form-data" method="post" class="cart">
                <?php do_action('before_wpneo_donate_field'); ?>
                <?php echo get_woocommerce_currency_symbol(); ?>
                <input type="number" step="any" min="0" placeholder="<?php echo $recomanded_price; ?>" name="wpneo_donate_amount_field" class="input-text amount wpneo_donate_amount_field text" value="<?php echo $recomanded_price; ?>" data-min-price="<?php echo $min_price ?>" data-max-price="<?php echo $max_price ?>" >
                <?php do_action('after_wpneo_donate_field'); ?>

                <input type="hidden" value="<?php echo esc_attr($post->ID); ?>" name="add-to-cart">
                <button type="submit" class="<?php echo apply_filters('add_to_donate_button_class', 'wpneo_donate_button'); ?>"><?php _e('Back Campaign', 'wp-crowdfunding'); ?></button>
 </form>

Here my code :

<form enctype="multipart/form-data" method="post" class="cart">
                <?php do_action('before_wpneo_donate_field');
                   $valAction = get_field('valeur_dune_action_admin_section');
                    $nbactions = 500000 / $valAction;
                ?>

                      <select type="number" step="any" name="actions" id="actions-select" name="wpneo_donate_amount_field" class="input-text amount wpneo_donate_amount_field text">
                       <?php 
                        $i = 1;
                        if ($nbactions != 0)
                        {
                            while ($i <= $nbactions) {
                            echo '<option value="' . $valAction * $i . '">' . $valAction * $i . '</option>';
                            $i++;
                            }
                        }

                            ?>
                        </select>

                <?php 
                echo get_woocommerce_currency_symbol();

                do_action('after_wpneo_donate_field'); ?>

                <input type="hidden" value="<?php echo esc_attr($post->ID); ?>" name="add-to-cart">


                <button type="submit" class="<?php echo apply_filters('add_to_donate_button_class', 'wpneo_donate_button'); ?>"><?php _e('Back Campaign', 'wp-crowdfunding'); ?></button>
</form>
1

At the select tag you have 2 name attribute

<select type="number" step="any" name="actions" id="actions-select" name="wpneo_donate_amount_field" class="input-text amount wpneo_donate_amount_field text">

Then, when you submit, it only collect the first defined name. (name="actions"). You have to delete this attribute. and using name="wpneo_donate_amount_field" only.

It should like

<select type="number" step="any" id="actions-select" name="wpneo_donate_amount_field" class="input-text amount wpneo_donate_amount_field text">
  • Rofl i'm so stupid ! didn't saw that, that works thanks you so much ! :) – Quentin Jul 18 '18 at 12:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.