How to add title and amount into the short code
-
First of all, great plugin. The source code is so neat I felt terrible for mucking it up with my hacks. I know as soon as I saw this plugin I thought great, but how do I set custom amounts and change the title of the button (on a per button basis?).
To do this I just added support for a couple of extra shortcode attributes:
[wp-stripe title=”My Button Title” amount=”20″]There are just a few edits to get this to work:
1. in includes/stripe-functions.php replace the function wp_stripe_shortcode with
function wp_stripe_shortcode( $atts ){ $options = get_option('wp_stripe_options'); extract(shortcode_atts(array( 'cards' => 'true', 'title' => $options['stripe_header'], 'amount' => '' ), $atts)); $settings = '?amount='.$amount.'&keepThis=true&TB_iframe=true&height=580&width=400'; $path = WP_STRIPE_PATH . '/includes/stripe-iframe.php'. $settings; $count = 1; if ( $options['stripe_modal_ssl'] == 'Yes' ) { $path = str_replace("http", "https", $path, $count); } if ( $cards == 'true' ) { $payments = '<div id="wp-stripe-types"></div>'; } return '<a class="thickbox" id="wp-stripe-modal-button" title="' . $title . '" href="' . $path . '">' . $title . '</a>' . $payments; }
2. in includes/stripe-display.php add
$amount = isset( $_GET['amount'] ) ? $_GET['amount']: '';
at the top of the wp_stripe_form function
3. in includes/stripe-display.php again replace the amount input with:
<input type="text" name="wp_stripe_amount" autocomplete="off" class="wp-stripe-card-amount" id="wp-stripe-card-amount" placeholder="<?php _e('Amount (CAD)', 'wp-stripe'); ?> *" value="<?php echo $amount; ?>" <?php echo $amount ? 'disabled="disabled"' : ''; ?> required />
That should do it. The amount in the box will be pre-set but it will not be editable if you add it to your shortcode. I can’t make any guarantees about this code working, so test it yourself. Good luck and thanks author for the great plugin.
- The topic ‘How to add title and amount into the short code’ is closed to new replies.