编辑文件:add-to-wishlist-button.js
import*as t from"@wordpress/interactivity";import*as e from"@woocommerce/stores/woocommerce/products";import*as o from"@woocommerce/stores/woocommerce/shopper-lists";var r={d:(t,e)=>{for(var o in e)r.o(e,o)&&!r.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:e[o]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)};const n=(i={getConfig:()=>t.getConfig,getContext:()=>t.getContext,store:()=>t.store},s={},r.d(s,i),s);var i,s;r.d({},{}),r.d({},{});const c="I acknowledge that using a private store means my plugin will inevitably break on the next store release.",a="wishlist",{state:l}=(0,n.store)("woocommerce/products",{},{lock:c}),{state:d,actions:u}=(0,n.store)("woocommerce/shopper-lists",{},{lock:c}),{state:m}=(0,n.store)("woocommerce/add-to-wishlist-button",{state:{get effectiveProductId(){const t=l.productInContext;return t?(0,n.getContext)().isVariableType&&"variable"===t.type?0:t.id:0},get currentItem(){const t=m.effectiveProductId;if(!t)return null;const e=d.lists[a];if(!e)return null;if(!(0,n.getContext)().isVariableType)return e.items.find(e=>e.id===t)??null;const o=(0,n.getContext)("woocommerce/add-to-cart-with-options"),r=o?.selectedAttributes??[];return e.items.find(e=>function(t,e,o){if(t.id!==e)return!1;const r=t.variation??[];return r.length===o.length&&o.every(t=>r.some(e=>e.attribute===t.attribute&&e.value.toLowerCase()===t.value.toLowerCase()))}(e,t,r))??null},get isInWishlist(){return null!==m.currentItem},get isDisabled(){return!!(0,n.getContext)().isPending||!m.effectiveProductId},get currentLabel(){const{addLabel:t,savedLabel:e,selectOptionsLabel:o}=(0,n.getConfig)("woocommerce/add-to-wishlist-button");return m.effectiveProductId?m.isInWishlist?e:t:o}},actions:{*onClickToggle(){const t=(0,n.getContext)();if(t.isPending)return;const e=m.effectiveProductId;if(!e)return;const o=m.currentItem;t.isPending=!0;try{if(o)yield u.removeItem(a,o.key);else{const t=(0,n.getContext)("woocommerce/add-to-cart-with-options"),o=l.mainProductInContext,r=new Map;o?.attributes?.forEach(t=>{t.name&&r.set(t.name,t.taxonomy||t.name)});const i=t?.selectedAttributes?.map(({attribute:t,value:e})=>({attribute:r.get(t)??t,value:e}))??[];yield u.addItem(a,{product_id:e,...i.length&&{variation:i}})}}finally{t.isPending=!1}}}},{lock:c});
保存
返回