Skip to content

Instantly share code, notes, and snippets.

@wabson
Created December 8, 2015 11:08
Show Gist options
  • Save wabson/8237f9942abfb2bc84a3 to your computer and use it in GitHub Desktop.
Save wabson/8237f9942abfb2bc84a3 to your computer and use it in GitHub Desktop.
Richmond CC extensions to Ninja forms
<?php
add_shortcode( 'ninja_forms_paypal', 'ninja_forms_paypal_shortcode' );
function ninja_forms_paypal_shortcode( $atts ){
global $ninja_forms_processing;
extract( shortcode_atts(
array(
'ref' => null,
'amount_field' => null,
'currency' => 'GBP',
'business' => null
), $atts )
);
if ( is_object ( $ninja_forms_processing ) ) {
$html = '<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top"><input name="cmd" type="hidden" value="_xclick" />';
if ( !empty( $ref ) ) {
$ref_with_values = preg_replace_callback("/\\{([0-9]+)\\}/", function($m) {
global $ninja_forms_processing;
return $ninja_forms_processing->get_field_value( $m[1] );
}, $ref);
$html .= '<input name="item_name" type="hidden" value="' . $ref_with_values . '" />';
}
if ( !empty( $amount ) ) {
$html .= '<input name="amount" type="hidden" value="' . $amount . '" />';
}
if ( !empty( $amount_field ) ) {
$amount = $ninja_forms_processing->get_field_value( $amount_field );
$html .= '<input name="amount" type="hidden" value="' . $amount . '" />';
}
if ( !empty( $currency ) ) {
$html .= '<input name="currency_code" type="hidden" value="' . $currency . '" />';
}
if ( !empty( $business ) ) {
$html .= '<input name="business" type="hidden" value="' . $business . '" />';
}
$html .= '<input alt="PayPal – The safer, easier way to pay online." name="submit" src="https://www.paypalobjects.com/en_GB/i/btn/btn_paynowCC_LG.gif" type="image" /><img src="https://www.paypalobjects.com/en_GB/i/scr/pixel.gif" alt="" width="1" height="1" border="0" /></form>';
return $html;
} else {
return '';
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment