mikerodriguez/acf-paypal-field

format_value_for_api outputs form

Opened this issue · 1 comments

The function "format_value_for_api" outputs the value instead of returning it. As this is the case you can not retrieve the value as a string via the get_field() function.

yes

/*
*  format_value_for_api()
*
*  This filter is appied to the $value after it is loaded from the db and before it is passed back to the api functions such as the_field
*
*  @type    filter
*  @since   3.6
*  @date    23/01/13
*
*  @param   $value  - the value which was loaded from the database
*  @param   $post_id - the $post_id from which the value was loaded
*  @param   $field  - the field array holding all the field options
*
*  @return  $value  - the modified value
*/

function format_value_for_api( $value, $post_id, $field )
{
    // defaults?

    $field = array_merge($this->defaults, $field);
    $enable_qty   = isset($field['enable_quantity']) ? $field['enable_quantity'] : '1';
    $button_label = ( isset($field['button_label']) && $field['button_label'] != "" ) ? $field['button_label'] : __("Pay Now",'acf');



                $output='<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_blank">
                    <input type="hidden" name="cmd" value="_xclick">
                    <input type="hidden" name="business" value="'.$field['paypal_email'].'">
                    <div class="item-field_name">'.$value['item_name'].'</div>
                    <input type="hidden" name="item_name" value="'.$value['item_name'].' ">
                    <div class="item-field_description">'.nl2br($value['item_description']).'</div>
                    <div class="item-field_price">Price: '.$value['price'].' '.$field['currency'].'</div>
                    <input type="hidden" name="amount" value="'.$value['price'].'">
                    <input type="hidden" name="no_shipping" value="2">
                    <input type="hidden" name="no_note" value="0">
                    <input type="hidden" name="currency_code" value="'.$field['currency'].'">
                    <input type="hidden" name="country" value="'.$field['country'].'">';

                    if($enable_qty == 1){

                    $output.='<div class="item-field_quantity">Qty: <input type="text" name="quantity" value="1"></div>';
                    }

                    $output.='<input type="hidden" name="bn" value="PP-BuyNowBF">
                    <input type="submit" class="item-field_button" value="'.$button_label.'">
                </form>';

    return $output;

}