cs_add_custom_json
Estimated reading: 1 minute
add_filter('cs_add_custom_json', 'custom_json', 10);PHP
function custom_json()
{
global $woocommerce;
if ($woocommerce) {
$items = $woocommerce->cart->get_cart();
if ($items) {
$jsonItems = [];
foreach ($items as $values) {
$price = get_post_meta($values['product_id'], '_price',true);
$destination_id = get_post_meta($values['product_id'], '_sf_destination_id', true);
if ($destination_id) {
$jsonItems[] = [
'DestinationId' => $destination_id,
'Amount' => $price
];
}
}
if ($jsonItems) {
return [
'TransactionInfo' => [
'Gifts' => $jsonItems
]
];
}
}
}
return [];
}PHP