← Back
Editing: settings-payments-cod.js
"use strict";(globalThis.webpackChunk_wcAdmin_webpackJsonp=globalThis.webpackChunk_wcAdmin_webpackJsonp||[]).push([[3501],{60431:(e,t,o)=>{o.d(t,{W:()=>n});var s=o(56427),i=o(39793);const n=({size:e="medium"})=>(0,i.jsx)("div",{className:`woocommerce-field-placeholder woocommerce-field-placeholder--${e}`,children:(0,i.jsx)(s.Placeholder,{})})},224:(e,t,o)=>{o.d(t,{w:()=>a});var s=o(56427),i=o(51609),n=o(39793);const a=({children:e})=>(0,n.jsx)(n.Fragment,{children:e});a.Layout=({children:e})=>((0,i.useEffect)(()=>{const e=document.getElementById("wpbody");e&&e.querySelector(".settings-layout")&&e.classList.add("has-settings-layout")},[]),(0,n.jsx)("div",{className:"settings-layout",children:e})),a.Section=({title:e,description:t,children:o,id:s})=>(0,n.jsxs)("div",{className:"settings-section",id:s,children:[(0,n.jsxs)("div",{className:"settings-section__details",children:[(0,n.jsx)("h2",{children:e}),(0,n.jsx)("p",{children:t})]}),(0,n.jsx)("div",{className:"settings-section__controls",children:o})]}),a.Actions=({children:e})=>(0,n.jsx)(s.Card,{className:"settings-card__wrapper ",children:(0,n.jsx)(s.CardBody,{className:"form__actions",children:e})}),a.Form=({children:e,onSubmit:t})=>(0,n.jsx)("form",{onSubmit:t,className:"settings-form",children:e})},56592:(e,t,o)=>{o.d(t,{C0:()=>n,lV:()=>l,mF:()=>a});var s=o(56427),i=o(39793);const n=({data:e,field:t,onChange:o})=>(0,i.jsx)(s.CheckboxControl,{label:t.label,help:t.description,checked:Boolean(t.getValue({item:e})),onChange:e=>o({[t.id]:e})}),a=({data:e,field:t,onChange:o})=>(0,i.jsx)(s.TextControl,{label:t.label,help:t.description,placeholder:t.placeholder,value:String(t.getValue({item:e})??""),onChange:e=>o({[t.id]:e})}),l=({data:e,field:t,onChange:o})=>(0,i.jsx)(s.TextareaControl,{label:t.label,help:t.description,value:String(t.getValue({item:e})??""),onChange:e=>o({[t.id]:e})})},65061:(e,t,o)=>{o.r(t),o.d(t,{SettingsPaymentsCod:()=>_,default:()=>p});var s=o(56427),i=o(27723),n=o(47143),a=o(40314),l=o(86087),r=o(35453),c=o(224),d=o(60431),m=o(56592),h=o(72002),u=o(39793);const _=()=>{const{createSuccessNotice:e,createErrorNotice:t}=(0,n.useDispatch)("core/notices"),{codSettings:o,isLoading:_}=(0,n.useSelect)(e=>({codSettings:e(a.paymentGatewaysStore).getPaymentGateway("cod"),isLoading:!e(a.paymentGatewaysStore).hasFinishedResolution("getPaymentGateway",["cod"])}),[]),{updatePaymentGateway:p,invalidateResolutionForStoreSelector:g}=(0,n.useDispatch)(a.paymentGatewaysStore),{invalidateResolution:b,invalidateResolutionForStoreSelector:y}=(0,n.useDispatch)(a.paymentSettingsStore),[w,f]=(0,l.useState)({}),[v,x]=(0,l.useState)(!1),[j,S]=(0,l.useState)(!1);(0,l.useEffect)(()=>{o&&(f({enabled:o.enabled,title:o.settings.title.value,description:o.description,instructions:o.settings.instructions.value,...(0,h.Z3)(o)}),S(!1))},[o]);const C=(0,l.useMemo)(()=>[{id:"enabled",label:(0,i.__)("Enable cash on delivery payments","woocommerce"),Edit:m.C0},{id:"title",label:(0,i.__)("Title","woocommerce"),description:(0,i.__)("Payment method name that the customer will see during checkout.","woocommerce"),placeholder:(0,i.__)("Cash on delivery payments","woocommerce"),Edit:m.mF},{id:"description",label:(0,i.__)("Description","woocommerce"),description:(0,i.__)("Payment method description that the customer will see during checkout.","woocommerce"),Edit:m.lV},{id:"instructions",label:(0,i.__)("Instructions","woocommerce"),description:(0,i.__)("Instructions that will be added to the thank you page and emails.","woocommerce"),Edit:m.lV},...(0,h.es)(o,(0,i.__)("cash on delivery","woocommerce"))],[o]);return(0,u.jsx)(c.w,{children:(0,u.jsx)(c.w.Layout,{children:(0,u.jsxs)(c.w.Form,{onSubmit:s=>{s.preventDefault(),(()=>{if(!o)return;x(!0);const s={title:String(w.title),instructions:String(w.instructions),...(0,h.YV)(w)};p("cod",{enabled:Boolean(w.enabled),description:String(w.description),settings:s}).then(()=>{S(!1),g("getPaymentGateway"),e((0,i.__)("Settings updated successfully","woocommerce"))}).catch(()=>{t((0,i.__)("Failed to update settings","woocommerce"))}).finally(()=>{x(!1),b("getPaymentProviders",[]),y("getOfflinePaymentGateways")})})()},children:[(0,u.jsx)(c.w.Section,{title:(0,i.__)("Enable and customise","woocommerce"),description:(0,i.__)("Choose how you want to present cash on delivery payments to your customers during checkout.","woocommerce"),children:_?(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(d.W,{size:"small"}),(0,u.jsx)(d.W,{size:"medium"}),(0,u.jsx)(d.W,{size:"large"}),(0,u.jsx)(d.W,{size:"large"}),(0,u.jsx)(d.W,{size:"medium"}),(0,u.jsx)(d.W,{size:"small"})]}):(0,u.jsx)(r.A,{data:w,fields:C,form:{layout:{type:"regular"},fields:["enabled","title","description","instructions","enable_for_methods","enable_for_virtual"]},onChange:e=>{f(t=>({...t,...e})),S(!0)}})}),(0,u.jsx)(c.w.Actions,{children:(0,u.jsx)(s.Button,{variant:"primary",type:"submit",isBusy:v,disabled:v||!j,children:(0,i.__)("Save changes","woocommerce")})})]})})})},p=_},72002:(e,t,o)=>{o.d(t,{es:()=>d,YV:()=>c,Z3:()=>r});var s=o(98846),i=o(27723);function n(e){const t=document.createElement("textarea");return t.innerHTML=e,t.value}var a=o(56592),l=o(39793);const r=e=>({enable_for_methods:Array.isArray(e.settings.enable_for_methods?.value)?e.settings.enable_for_methods.value:[],enable_for_virtual:"yes"===e.settings.enable_for_virtual?.value}),c=e=>({enable_for_methods:Array.isArray(e.enable_for_methods)?e.enable_for_methods:[],enable_for_virtual:e.enable_for_virtual?"yes":"no"}),d=(e,t)=>{const o=e?.settings.enable_for_methods?.options?(r=e.settings.enable_for_methods.options,Object.entries(r).map(([e,t])=>({label:n(e),value:e,children:Object.entries(t).map(([e,t])=>({value:e,label:n(t)}))}))):[];var r;const c=(0,i.__)("Select shipping methods for which this payment method is enabled.","woocommerce");return[{id:"enable_for_methods",label:(0,i.__)("Enable for shipping methods","woocommerce"),description:c,Edit:({data:e,field:t,onChange:i})=>{const n=t.getValue({item:e});return(0,l.jsx)(s.TreeSelectControl,{label:t.label,help:c,options:o,value:Array.isArray(n)?n:[],onChange:e=>i({[t.id]:e}),selectAllLabel:!1})}},{id:"enable_for_virtual",label:(0,i.__)("Accept for virtual orders","woocommerce"),description:(0,i.sprintf)((0,i.__)("Accept %s if the order is virtual","woocommerce"),t),Edit:a.C0}]}}}]);
Save File
Cancel