Im trying to return first key & value from an external array, This array currently outputs like so Company name - €10.00 Company Name2 - €20.00 until the array is finished.
protected function _results_text($results)
{
$output = '';
if( ! empty( $results ) ) : foreach ( $results as $result ) :
$output .= '';
if ( count( $result['quotes']) > 0 ) :
foreach ( $result['quotes'] as $quote ) :
if ( $quote->is_available() ) :
$output .= $quote->provider['name'] .' - '. $quote->final_price;
else:
$output .= $quote->provider['name'] . 'Not quoting';
endif;
endforeach;
else:
$output .= 'Please call us for a quote on 1800-828-800';
endif;
endforeach; endif;
return $output;
}
I have tried adding a reset in the form of adding it to the line:
foreach ( $result['quotes'] as $quote ) :
But this didnt work (Sorry i dont have the code anymore)
This is a custom plugin for Wordpress Ninja Forms that pulls data from an external API and emails / displays the quote results on page.
I just need the first $quote->provider['name'] and $quote->final_price to be returned
Edit - here is the results function:
public function results()
{
if( $results = $this->get_cache('results') ) {
return $results;
}
$results = [];
if ( isset( $this->response->Quotes->Type ) ) {
foreach($this->response->Quotes->Type as $quoteTypeResults) {
$type = $quoteTypeResults->Desc;
$warnings = array();
foreach($quoteTypeResults->CriticalWarning as $warning) {
$warnings[] = (string) $warning;
}
$quotes = $this->process_quotes($quoteTypeResults->Company, $this->modifiers);
$results[] = array(
'type' => $quoteTypeResults->Desc,
'warnings' => $warnings,
'quotes' => $quotes
);
}
}
return $this->set_cache('results', $results);
}