← Back
Editing: product-sale-badge.js
(globalThis.webpackChunkwebpackWcBlocksMainJsonp=globalThis.webpackChunkwebpackWcBlocksMainJsonp||[]).push([[4442],{2374:(e,t,o)=>{"use strict";o.d(t,{p:()=>a});var n=o(4921),r=o(73993),s=o(25028),c=o(63512);const a=e=>{const t=(e=>{const t=(0,r.isObject)(e)?e:{style:{}};let o=t.style;return(0,r.isString)(o)&&(o=JSON.parse(o)||{}),(0,r.isObject)(o)||(o={}),{...t,style:o}})(e),o=(0,c.BK)(t),a=(0,c.aR)(t),l=(0,c.fo)(t),i=(0,s.x)(t);return{className:(0,n.A)(i.className,o.className,a.className,l.className),style:{...i.style,...o.style,...a.style,...l.style}}}},25028:(e,t,o)=>{"use strict";o.d(t,{x:()=>r});var n=o(73993);const r=e=>{const t=(0,n.isObject)(e.style.typography)?e.style.typography:{},o=(0,n.isString)(t.fontFamily)?t.fontFamily:"";return{className:e.fontFamily?`has-${e.fontFamily}-font-family`:o,style:{fontSize:e.fontSize?`var(--wp--preset--font-size--${e.fontSize})`:t.fontSize,fontStyle:t.fontStyle,fontWeight:t.fontWeight,letterSpacing:t.letterSpacing,lineHeight:t.lineHeight,textDecoration:t.textDecoration,textTransform:t.textTransform}}}},63512:(e,t,o)=>{"use strict";o.d(t,{BK:()=>i,aR:()=>u,fo:()=>p});var n=o(4921),r=o(67356),s=o(49786),c=o(73993);function a(e={}){const t={};return(0,s.getCSSRules)(e,{selector:""}).forEach(e=>{t[e.key]=e.value}),t}function l(e,t){return e&&t?`has-${(0,r.c)(t)}-${e}`:""}function i(e){const{backgroundColor:t,textColor:o,gradient:r,style:s}=e,i=l("background-color",t),u=l("color",o),p=function(e){if(e)return`has-${e}-gradient-background`}(r),d=p||s?.color?.gradient;return{className:(0,n.A)(u,p,{[i]:!d&&!!i,"has-text-color":o||s?.color?.text,"has-background":t||s?.color?.background||r||s?.color?.gradient,"has-link-color":(0,c.isObject)(s?.elements?.link)?s?.elements?.link?.color:void 0}),style:a({color:s?.color||{}})}}function u(e){const t=e.style?.border||{};return{className:function(e){const{borderColor:t,style:o}=e,r=t?l("border-color",t):"";return(0,n.A)({"has-border-color":!!t||!!o?.border?.color,[r]:!!r})}(e),style:a({border:t})}}function p(e){return{className:void 0,style:a({spacing:e.style?.spacing||{}})}}},72334:(e,t,o)=>{"use strict";o.r(t),o.d(t,{Block:()=>d,default:()=>g});var n=o(27723),r=o(70910),s=o(4921),c=o(14656),a=o(62796),l=o(2374),i=o(41616),u=(o(94324),o(34162)),p=o(10790);const d=e=>{const{className:t,align:o,isDescendentOfSingleProductTemplate:i}=e,d=(0,l.p)(e),{parentClassName:g}=(0,a.useInnerBlockLayoutContext)(),{product:f}=(0,a.useProductDataContext)();if(!(f.id&&f.on_sale||i))return null;const m="amount"===e.badgeContent||"percentage"===e.badgeContent;let y=e.saleText||(0,n.__)("Sale","woocommerce");if(m&&"grouped"!==f.type){const t="prices"in f?f.prices:void 0,o=(0,u.y)(t);if(o){if("percentage"===e.badgeContent&&0===o.percentage)return null;const s="percentage"===e.badgeContent?(0,n.sprintf)(/* translators: %s: discount percentage. %% is the percent sign. */ /* translators: %s: discount percentage. %% is the percent sign. */ (0,n.__)("%s%%","woocommerce"),o.percentage):(0,r.formatPrice)(o.amount,(0,r.getCurrencyFromPriceResponse)(t));y="variable"===f.type?(0,n.sprintf)(/* translators: %s: approximate discount for a variable product in the editor. */ /* translators: %s: approximate discount for a variable product in the editor. */ (0,n.__)("Up to %s","woocommerce"),s):`${e.prefix??""}${s}${e.suffix??""}`}}const b="string"==typeof o?`wc-block-components-product-sale-badge--align-${o}`:"";return(0,p.jsx)("div",{className:(0,s.A)("wc-block-components-product-sale-badge",t,b,{[`${g}__product-onsale`]:g},d.className),style:d.style,children:(0,p.jsx)(c.Label,{label:y,screenReaderLabel:(0,n.sprintf)(/* translators: %s: sale badge text. */ /* translators: %s: sale badge text. */ (0,n.__)("Product on sale: %s","woocommerce"),y)})})},g=(0,i.withProductDataContext)(d)},34162:(e,t,o)=>{"use strict";o.d(t,{y:()=>n});const n=e=>{const t=Number(e?.regular_price),o=t-Number(e?.price);return t>0&&o>0?{amount:o,percentage:Math.round(o/t*100)}:null}},94324:()=>{}}]);
Save File
Cancel