跳到主要内容

可用的过滤器

本文档列出了当前可用的过滤器,并为每个过滤器提供了使用信息。有关注册过滤器的信息,请访问 结账 - 过滤器注册 页面。

购物车商品项过滤器

以下 购物车商品项过滤器 可用:

  • cartItemClass
  • cartItemPrice
  • itemName
  • saleBadgePriceFormat
  • showRemoveItemLink
  • subtotalPriceFormat

以下截图显示了各个过滤器影响的部分:

购物车商品项

订单摘要商品项过滤器

以下 订单摘要商品项过滤器 可用:

  • cartItemClass
  • cartItemPrice
  • itemName
  • subtotalPriceFormat

以下截图显示了各个过滤器影响的部分:

订单摘要商品项

订单总计页脚商品项过滤器

以下 订单总计页脚商品项过滤器 可用:

  • totalLabel
  • totalValue

结账和提交订单按钮过滤器

以下 结账和提交订单按钮过滤器 可用:

  • proceedToCheckoutButtonLabel
  • proceedToCheckoutButtonLink
  • placeOrderButtonLabel

优惠券过滤器

以下 优惠券过滤器 可用:

  • coupons
  • showApplyCouponNotice
  • showRemoveCouponNotice

附加购物车和结账内部块类型过滤器

以下 附加购物车和结账内部块类型过滤器 可用:

  • additionalCartCheckoutInnerBlockTypes

组合过滤器

过滤器也可以进行组合。以下示例展示了如何组合一些可用的过滤器。

const { registerCheckoutFilters } = window.wc.blocksCheckout;

const isOrderSummaryContext = ( args ) => args?.context === 'summary';

const modifyCartItemClass = ( defaultValue, extensions, args ) => {
if ( isOrderSummaryContext( args ) ) {
return 'my-custom-class';
}
return defaultValue;
};

const modifyCartItemPrice = ( defaultValue, extensions, args ) => {
if ( isOrderSummaryContext( args ) ) {
return '<price/> for all items';
}
return defaultValue;
};

const modifyItemName = ( defaultValue, extensions, args ) => {
if ( isOrderSummaryContext( args ) ) {
return `${ defaultValue }`;
}
return defaultValue;
};

const modifySubtotalPriceFormat = ( defaultValue, extensions, args ) => {
if ( isOrderSummaryContext( args ) ) {
return '<price/> per item';
}
return defaultValue;
};

registerCheckoutFilters( 'example-extension', {
cartItemClass: modifyCartItemClass,
cartItemPrice: modifyCartItemPrice,
itemName: modifyItemName,
subtotalPriceFormat: modifySubtotalPriceFormat,
} );

故障排除

如果您以管理员身份登录到商店,如果您的过滤器未正常工作,您应该会看到类似以下的错误。该错误也会显示在您的控制台中。

故障排除