{"id":7500,"date":"2021-07-12T09:12:55","date_gmt":"2021-07-12T09:12:55","guid":{"rendered":"https:\/\/docs.campaignsuite.nl\/docs\/developers\/filters\/cs_add_custom_json\/"},"modified":"2021-07-12T09:15:55","modified_gmt":"2021-07-12T09:15:55","slug":"cs_add_custom_json","status":"publish","type":"docs","link":"https:\/\/docs.campaignsuite.nl\/en\/docs\/developers\/filters\/cs_add_custom_json\/","title":{"rendered":"cs_add_custom_json"},"content":{"rendered":"\t\t<div data-elementor-type=\"wp-post\" data-elementor-id=\"7500\" class=\"elementor elementor-7500\">\n\t\t\t\t\t\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-40ccf79 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"40ccf79\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-5d4bbc2\" data-id=\"5d4bbc2\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t\t\t<div class=\"elementor-element elementor-element-27b8907 elementor-widget elementor-widget-text-editor\" data-id=\"27b8907\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<h4>Description<\/h4><p>With this filter you can add your own custom JSON to the API call to Findock or Converse. This JSON will be added to the root of the JSON object.<\/p><h4>Use<\/h4>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-872705f elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"872705f\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-d2e89ce\" data-id=\"d2e89ce\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t\t\t<div class=\"elementor-element elementor-element-17899e8 elementor-widget elementor-widget-docly_code_syntax_highlighter\" data-id=\"17899e8\" data-element_type=\"widget\" data-widget_type=\"docly_code_syntax_highlighter.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t                    <div class=\"docly-source-code prism\" data-lng-type=\"php\">\r\n\t\t\t<pre>\r\n\t\t\t\t<code class=\"language-php\">\r\n\t\t\t\t\tadd_filter(&#039;cs_add_custom_json&#039;, &#039;custom_json&#039;, 10);\t\t\t\t<\/code>\r\n\t\t\t<\/pre>\r\n            <\/div>\r\n                \t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-ccdf99a elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"ccdf99a\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-081a419\" data-id=\"081a419\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t\t\t<div class=\"elementor-element elementor-element-f6ca926 elementor-widget elementor-widget-text-editor\" data-id=\"f6ca926\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<h4>Example<\/h4><p>The example below loops through Woocommerce items in a shopping cart and checks whether Destination IDs have been set. If so, these will be passed in the JSON call to the CampaignSuite API.<\/p>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-91fcb8d elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"91fcb8d\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-e93cb31\" data-id=\"e93cb31\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t\t\t<div class=\"elementor-element elementor-element-b5bbf99 elementor-widget elementor-widget-docly_code_syntax_highlighter\" data-id=\"b5bbf99\" data-element_type=\"widget\" data-widget_type=\"docly_code_syntax_highlighter.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t                    <div class=\"docly-source-code prism\" data-lng-type=\"php\">\r\n\t\t\t<pre>\r\n\t\t\t\t<code class=\"language-php\">\r\n\t\t\t\t\tfunction custom_json()\n{\n    global $woocommerce;\n    if ($woocommerce) {\n        $items = $woocommerce-&gt;cart-&gt;get_cart();\n        if ($items) {\n            $jsonItems = [];\n            foreach ($items as $values) {\n                $price = get_post_meta($values[&#039;product_id&#039;], &#039;_price&#039;,true);\n                $destination_id = get_post_meta($values[&#039;product_id&#039;], &#039;_sf_destination_id&#039;, true);\n                if ($destination_id) {\n                    $jsonItems[] = [\n                        &#039;DestinationId&#039; =&gt; $destination_id,\n                        &#039;Amount&#039; =&gt; $price\n                    ];\n                }\n            }\n            if ($jsonItems) {\n                return [\n                    &#039;TransactionInfo&#039; =&gt; [\n                        &#039;Gifts&#039; =&gt; $jsonItems\n                    ]\n                ];\n            }\n        }\n    }\n    return [];\n}\t\t\t\t<\/code>\r\n\t\t\t<\/pre>\r\n            <\/div>\r\n                \t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t\t\t\t<\/div>\n\t\t","protected":false},"excerpt":{"rendered":"<p>Description With this filter you can add your own custom JSON to the API call to Findock or Converse. This JSON will be added to the root of the JSON object. Use add_filter(&#039;cs_add_custom_json&#039;, &#039;custom_json&#039;, 10); Example The example below loops through Woocommerce items in a shopping cart and checks whether Destination IDs have been set. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":7407,"menu_order":4,"comment_status":"open","ping_status":"closed","template":"","doc_tag":[],"class_list":["post-7500","docs","type-docs","status-publish","hentry","no-post-thumbnail"],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.campaignsuite.nl\/en\/wp-json\/wp\/v2\/docs\/7500","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/docs.campaignsuite.nl\/en\/wp-json\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/docs.campaignsuite.nl\/en\/wp-json\/wp\/v2\/types\/docs"}],"author":[{"embeddable":true,"href":"https:\/\/docs.campaignsuite.nl\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.campaignsuite.nl\/en\/wp-json\/wp\/v2\/comments?post=7500"}],"version-history":[{"count":6,"href":"https:\/\/docs.campaignsuite.nl\/en\/wp-json\/wp\/v2\/docs\/7500\/revisions"}],"predecessor-version":[{"id":7509,"href":"https:\/\/docs.campaignsuite.nl\/en\/wp-json\/wp\/v2\/docs\/7500\/revisions\/7509"}],"up":[{"embeddable":true,"href":"https:\/\/docs.campaignsuite.nl\/en\/wp-json\/wp\/v2\/docs\/7407"}],"wp:attachment":[{"href":"https:\/\/docs.campaignsuite.nl\/en\/wp-json\/wp\/v2\/media?parent=7500"}],"wp:term":[{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/docs.campaignsuite.nl\/en\/wp-json\/wp\/v2\/doc_tag?post=7500"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}