• This post is a donation of code (or at least the start of code) to extend the “wp_paypal_payment_box” shortcode to support a “max_quantity” attribute that (if greater than one) will render a select box with the number of items that the user is intending to buy. The selected number is submitted to PayPal via the standard “quantity” variable.

    Here is the patch I have made to v4.8 of this plugin:

    diff -U 3 -r trunk/shortcode_view.php update/shortcode_view.php
    --- trunk/shortcode_view.php	2016-01-21 22:35:46.000000000 -0600
    +++ update/shortcode_view.php	2016-01-21 22:36:12.000000000 -0600
    @@ -97,6 +97,7 @@
             'email' => '',
             'currency' => 'USD',
             'options' => 'Payment for Service 1:15.50|Payment for Service 2:30.00|Payment for Service 3:47.00',
    +        'max_quantity' => '',
             'return' => site_url(),
             'cbt' => '',
             'reference' => 'Your Email Address',
    @@ -144,6 +145,16 @@
                     <select class="wp_paypal_button_options">
         <?php echo $html_options; ?>
                     </select>
    +              <?php if ($max_quantity > 1) { ?>
    +                <label for="quantity">Quantity:</label>
    +                <select name="quantity" style="width: 5em;">
    +                <?php
    +                  for ($i = 1; $i <= $max_quantity; $i++) {
    +                ?>
    +                  <option><?php echo $i; ?></option>
    +                <?php } ?>
    +                </select>
    +              <?php } ?>
                 </div>
    
                         <?php

    https://ww.wp.xz.cn/plugins/wordpress-easy-paypal-payment-or-donation-accept-plugin/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter etetech

    (@etetech)

    I’ll clarify that the above code works as is, but needs to following:
    * The inline style on the additional select box is not ideal. Feel free to give it a proper class name, and put the styling in the CSS.
    * Additions to the short-code documentation are obviously missing.

    Plugin Contributor mbrsolution

    (@mbrsolution)

    Thank you for your information and contributed time to share your code. The plugin developers will investigate further your code.

    Thank you

    The best way to handle this is via a filter. I can add a filter in there so you can add your custom code without having to modify the core code. Will that help?

    Thread Starter etetech

    (@etetech)

    I’m happy to leverage some functionality that would avoid the need to modify the core code, but I would prefer if the plugin itself supported the quantity field natively. I know there are some styling and documentation concerns, but the implementation itself seems relatively straightforward. As written, if the max_quantity is missing or is one, then the plugin is completely backward compatible since the field itself is not rendered.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Ability to enter a quantity’ is closed to new replies.