/** * Shortcode to output a number box - [stripe_radio] * * @since 2.0.0 */ function stripe_radio($attr) { static $counter = 1; global $sc_script_options; $attr = shortcode_atts(array('id' => '', 'label' => '', 'default' => '', 'options' => '', 'is_quantity' => 'false', 'amounts' => '', 'is_amount' => 'false'), $attr, 'stripe_radio'); $id = $attr['id']; $label = $attr['label']; $default = $attr['default']; $options = $attr['options']; $is_quantity = $attr['is_quantity']; $amounts = $attr['amounts']; $is_amount = $attr['is_amount']; Shortcode_Tracker::add_new_shortcode('stripe_radio_' . $counter, 'stripe_radio', $attr, false); // Check for ID and if it doesn't exist then we will make our own if ($id == '') { $id = 'sc_cf_radio_' . $counter; } $options = explode(',', $options); if (!empty($amounts)) { $amounts = explode(',', str_replace(' ', '', $amounts)); if (count($options) != count($amounts)) { Shortcode_Tracker::update_error_count(); if (current_user_can('manage_options')) { Shortcode_Tracker::add_error_message('<h6>' . __('Admin note: Your number of options and amounts are not equal.', 'stripe') . '</h6>'); } else { return ''; } } } if ($is_amount == 'true') { if (current_user_can('manage_options')) { echo '<h6>' . sprintf(__('Admin note: The "is_amount" attribute is deprecated and will be removed in an upcoming release. Please use the new "amounts" attribute instead. %s', 'stripe'), '<a href="' . SC_WEBSITE_BASE_URL . 'docs/shortcodes/stripe-custom-fields/" target="_blank">' . __('See Documentation', 'stripe') . '</a>') . '</h6>'; } } $quantity_html = 'true' == $is_quantity ? 'data-sc-quantity="true" ' : ''; $quantity_class = 'true' == $is_quantity ? ' sc-cf-quantity' : ''; $amount_class = !empty($amounts) || $is_amount == 'true' ? ' sc-cf-amount' : ''; $html = !empty($label) ? '<label>' . $label . '</label>' : ''; $html .= '<div class="sc-radio-group">'; $i = 1; foreach ($options as $option) { $option = trim($option); $value = $option; if (empty($default)) { $default = $option; } if ($is_amount == 'true') { $currency = strtoupper($sc_script_options['script']['currency']); $amount = Stripe_Checkout_Misc::to_formatted_amount($option, $currency); if ($currency == 'USD') { $option_name = '$' . $amount; } else { $option_name = $amount . ' ' . $currency; } } else { if (!empty($amounts)) { $value = $amounts[$i - 1]; } } if ($default == $option && $is_quantity != 'true' && !empty($amounts)) { $sc_script_options['script']['amount'] = $value; } // Don't use built-in checked() function here for now since we need "checked" in double quotes. $html .= '<label title="' . esc_attr($option) . '">'; $html .= '<input type="radio" name="sc_form_field[' . esc_attr($id) . ']" value="' . (isset($option_name) ? $option_name : $option) . '" ' . 'data-sc-price="' . esc_attr($value) . '" ' . ($default == $option ? 'checked="checked"' : '') . ' class="' . esc_attr($id) . '_' . $i . $quantity_class . $amount_class . '" data-parsley-errors-container=".' . apply_filters('sc_form_group_class', 'sc-form-group') . '" ' . $quantity_html . '>'; $html .= '<span>' . (isset($option_name) ? $option_name : $option) . '</span>'; $html .= '</label>'; $i++; } $html .= '</div>'; //sc-radio-group $attr['currency'] = strtoupper($sc_script_options['script']['currency']); $args = $this->get_args($id, $attr, $counter); // Incrememnt static counter $counter++; $this->total_fields(); return '<div class="' . apply_filters('sc_form_group_class', 'sc-form-group') . '">' . apply_filters('sc_stripe_radio', $html, $args) . '</div>'; }
/** * [stripe_recurring_total] shortcode. */ public function recurring_total($attr) { global $sc_script_options; static $counter = 1; $attr = shortcode_atts(array('label' => __('Recurring payment:', 'sc_sub') . ' '), $attr, 'stripe_recurring_total'); $label = $attr['label']; $currency = strtoupper($sc_script_options['script']['currency']); $amount = $sc_script_options['script']['amount']; $setup_fee = isset($sc_script_options['script']['setupFee']) ? $sc_script_options['script']['setupFee'] : 0; Shortcode_Tracker::add_new_shortcode('stripe_recurring_total_' . $counter, 'stripe_total', $attr, false); $html = $label . ' '; $html .= '<span class="' . apply_filters('sc_recurring_total_amount_class', 'sc-recurring-total-amount') . '">'; // USD only: Show dollar sign on left of amount. if ($currency === 'USD') { $html .= '$'; } $html .= Stripe_Checkout_Misc::to_formatted_amount($amount + $setup_fee, $currency); // Non-USD: Show currency on right of amount. if ($currency !== 'USD') { $html .= ' ' . $currency; } $html .= '</span>'; //sc-recurring-total-amount $counter++; // Set args to send with filter $args = array(); $args['label'] = $label; $args['currency'] = $currency; $args['amount'] = $amount; $args['setup_fee'] = $setup_fee; return '<div class="' . apply_filters('sc_form_group_class', 'sc-form-group') . '">' . apply_filters('sc_stripe_recurring_total', $html, $args) . '</div>'; }