Categories
February 9, 2024
Account Compare
]*>.*?<\/sup>/is', '', $value);
$value = wp_strip_all_tags($value);
$value = html_entity_decode($value, ENT_QUOTES | ENT_HTML5, get_bloginfo('charset') ?: 'UTF-8');
$value = preg_replace('/[\x{00A0}\s]+/u', ' ', $value);
return trim($value);
}
}
if (!function_exists('lsg_clean_schema_array')) {
function lsg_clean_schema_array($array) {
foreach ($array as $key => $value) {
if (is_array($value)) {
$value = lsg_clean_schema_array($value);
}
if ($value === '' || $value === null || $value === []) {
unset($array[$key]);
} else {
$array[$key] = $value;
}
}
return $array;
}
}
?>
} elseif ($type === 'text' && get_sub_field('compare_text')) {
$field_data[] = get_sub_field('compare_text');
} else {
$field_data[] = '
}
$value_found = true;
}
}
}
if (!$value_found) {
$field_data[] = ' ';
}
}
}
$compare_values[] = $field_data;
$a++;
}
}
$total_accounts = count($accounts);
?>
Features | |
|---|---|
'Organization',
'@id' => trailingslashit($site_url) . '#organization',
'name' => $site_name,
'url' => $site_url,
];
$item_list = [];
foreach ($accounts as $i => $account) {
$account_name = lsg_text_without_sup($account['name'] ?? '');
$account_description = lsg_text_without_sup($account['brief_description'] ?? '');
if (empty($account_description)) {
$account_description = lsg_text_without_sup($account['description'] ?? '');
}
if (empty($account_name)) {
continue;
}
$account_url = '';
if (!empty($account['links']) && is_array($account['links'])) {
foreach ($account['links'] as $account_link) {
$link_url = $account_link['link_url'] ?? '';
if (!empty($link_url) && $link_url !== '#') {
$account_url = esc_url_raw($link_url);
break;
}
}
}
if (empty($account_url)) {
$account_url = $current_url . '#financial-product-' . sanitize_title($account_name);
}
$product_id = $current_url . '#financial-product-' . sanitize_title($account_name);
$additional_properties = [];
if (!empty($compare_fields) && !empty($compare_values)) {
foreach ($compare_fields as $row_index => $compare_field) {
$field_name = lsg_text_without_sup($compare_field);
$field_value = $compare_values[$row_index][$i] ?? '';
$field_value_clean = lsg_text_without_sup($field_value);
if (empty($field_value_clean) && strpos((string) $field_value, 'compare-check') !== false) {
$field_value_clean = 'Yes';
}
if (!empty($field_name) && !empty($field_value_clean)) {
$additional_properties[] = [
'@type' => 'PropertyValue',
'name' => $field_name,
'value' => $field_value_clean,
];
}
}
}
$product = [
'@type' => 'FinancialProduct',
'@id' => $product_id,
'name' => $account_name,
'description' => $account_description,
'category' => 'Bank Account',
'provider' => [
'@id' => $provider['@id'],
],
'brand' => [
'@id' => $provider['@id'],
],
'url' => $account_url,
'mainEntityOfPage' => $current_url,
];
if (!empty($additional_properties)) {
$product['additionalProperty'] = $additional_properties;
}
if (!empty($account['open_account_url']) && $account['open_account_url'] !== '#') {
$open_account_url = esc_url_raw($account['open_account_url']);
$open_account_text = lsg_text_without_sup($account['open_account_text'] ?? 'Open Account');
$product['offers'] = [
'@type' => 'Offer',
'url' => $open_account_url,
'seller' => [
'@id' => $provider['@id'],
],
];
$product['potentialAction'] = [
'@type' => 'ApplyAction',
'name' => $open_account_text ?: 'Open Account',
'target' => $open_account_url,
];
}
$item_list[] = [
'@type' => 'ListItem',
'position' => $i + 1,
'item' => lsg_clean_schema_array($product),
];
}
if (!empty($item_list)) {
$schema = [
'@context' => 'https://schema.org',
'@type' => 'ItemList',
'@id' => $current_url . '#financial-products',
'name' => get_bloginfo('name') . ' Financial Products',
'provider' => $provider,
'itemListElement' => $item_list,
];
?>