@@ -98,3 +98,81 @@ function VFA_RestApi( WP_REST_Request $request ) {
9898 'callback ' => 'VFA_RestApi ' ,
9999 ) );
100100} );
101+
102+ add_action ('wp ' , function () {
103+ $ headers = headers_list ();
104+ $ cookies = array ();
105+
106+
107+
108+ foreach ($ headers as $ header ) {
109+ if (strpos ($ header , 'Set-Cookie: ' ) === 0 ) {
110+ if (preg_match ('/path=(.*);/i ' , $ header )) {
111+ $ cookies [] = preg_replace ('/path=(.*);/i ' , 'path=/; ' , $ header );
112+ } else if (preg_match ('/path=(.*)/i ' , $ header )) {
113+ $ cookies [] = preg_replace ('/path=(.*)/i ' , 'path=/ ' , $ header );
114+ }
115+
116+ }
117+ }
118+
119+ for ($ i =0 ; $ i < count ($ cookies ); $ i ++) {
120+ if ($ i == 0 ) {
121+ header ($ cookies [$ i ]);
122+ } else {
123+ header ($ cookies [$ i ], false );
124+ }
125+ }
126+ },99 );
127+ add_action ('woocommerce_add_to_cart ' , function () {
128+ $ headers = headers_list ();
129+ $ cookies = array ();
130+
131+
132+
133+ foreach ($ headers as $ header ) {
134+ if (strpos ($ header , 'Set-Cookie: ' ) === 0 ) {
135+ if (preg_match ('/path=(.*);/i ' , $ header )) {
136+ $ cookies [] = preg_replace ('/path=(.*);/i ' , 'path=/; ' , $ header );
137+ } else if (preg_match ('/path=(.*)/i ' , $ header )) {
138+ $ cookies [] = preg_replace ('/path=(.*)/i ' , 'path=/ ' , $ header );
139+ }
140+
141+ }
142+ }
143+
144+
145+ for ($ i =0 ; $ i < count ($ cookies ); $ i ++) {
146+ if ($ i == 0 ) {
147+ header ($ cookies [$ i ]);
148+ } else {
149+ header ($ cookies [$ i ], false );
150+ }
151+ }
152+ },99 );
153+
154+ add_action ('shutdown ' , function () {
155+ $ headers = headers_list ();
156+ $ cookies = array ();
157+
158+
159+
160+ foreach ($ headers as $ header ) {
161+ if (strpos ($ header , 'Set-Cookie: ' ) === 0 ) {
162+ if (preg_match ('/path=(.*);/i ' , $ header )) {
163+ $ cookies [] = preg_replace ('/path=(.*);/i ' , 'path=/; ' , $ header );
164+ } else if (preg_match ('/path=(.*)/i ' , $ header )) {
165+ $ cookies [] = preg_replace ('/path=(.*)/i ' , 'path=/ ' , $ header );
166+ }
167+
168+ }
169+ }
170+
171+ for ($ i =0 ; $ i < count ($ cookies ); $ i ++) {
172+ if ($ i == 0 ) {
173+ header ($ cookies [$ i ]);
174+ } else {
175+ header ($ cookies [$ i ], false );
176+ }
177+ }
178+ }, 1 );
0 commit comments