# 短代码的钩子替代方案

以下是加载购物车/结账短代码和块时运行的钩子。其中一些是通用的 WooCommerce 生命周期钩子，另一些是特定于购物车和结账页面的钩子。这些是通过记录每次 `do_action` 和 `apply_filters` 的调用，并审查提到 "钩子" 和 "过滤器" 的旧 [WooCommerce Blocks 仓库](https://github.com/woocommerce/woocommerce-blocks/) 中的问题而生成的。

## 术语表

| 图标 | 描述 |
| --- | --- |
| ✅ | 完全支持 |
| 🔶 | 部分支持 |
| ❌ | 不支持 |
| ❓ | 未知 |

如果一个钩子被标记为未知 ❓，这意味着我们无法验证该钩子是否受支持，原因不明。 随着时间的推移，我们将尝试验证更多这些钩子。 目标是使所有表格中都不要再有任何具有未知 ❓ 状态的钩子。

### WooCommerce 生命周期 _操作_

这些钩子在每个 WooCommerce 页面加载时运行，有些会影响块，有些不会，有些只部分影响它们。

| 旧钩子 | 在块中有效？ | 备注 |
| --- | --- | --- |
| `woocommerce_load_cart_from_session` | 完全支持 ✅ | |
| `woocommerce_cart_loaded_from_session` | 完全支持 ✅ | |
| `woocommerce_set_cart_cookies` | 完全支持 ✅ | |
| `woocommerce_shipping_zone_loaded` | 完全支持 ✅ | |
| `woocommerce_check_cart_items` | 完全支持 ✅ | 建议使用 `woocommerce_store_api_validate_cart_item` |
| `woocommerce_before_calculate_totals` | 完全支持 ✅ | |
| `woocommerce_shipping_init` | 完全支持 ✅ | |
| `woocommerce_load_shipping_methods` | 完全支持 ✅ | |
| `woocommerce_cart_calculate_fees` | 完全支持 ✅ | |
| `woocommerce_calculate_totals` | 完全支持 ✅ | |
| `woocommerce_after_calculate_totals` | 完全支持 ✅ | |
| `woocommerce_cart_updated` | 完全支持 ✅ | |
| `woocommerce_before_get_rates_for_package` | 完全支持 ✅ | |
| `woocommerce_after_get_rates_for_package` | 完全支持 ✅ | |
| `woocommerce_checkout_init` | 完全支持 ✅ | |
| `woocommerce_customer_loaded` | 完全支持 ✅ | |

### WooCommerce 生命周期 _筛选_

本节描述了 WooCommerce 提供的各种生命周期事件，这些事件允许您通过 _筛选_ 来修改 WooCommerce 的行为。

**什么是 _筛选_？**

_筛选_ 允许您在 WooCommerce 的特定事件发生时，修改其默认行为。  您可以将自定义函数连接到这些 _筛选_，以便在事件发生时执行您的代码。

**如何使用 _筛选_？**

要使用 _筛选_，您需要：

1.  找到您想要修改的事件的 _筛选_ 名称。
2.  使用 `add_filter()` 函数，将您的自定义函数连接到该 _筛选_。
3.  在您的自定义函数中，修改事件的默认值。

**示例：**

假设您想修改 WooCommerce 订单总价的计算方式。  您可以使用 `woocommerce_order_total` _筛选_ 来实现这一点。

```php
<?php
add_filter( 'woocommerce_order_total', 'custom_order_total' );

function custom_order_total( $total ) {
  // 在这里添加您的自定义逻辑来计算订单总价
  $total = $total + 10; // 例如，增加 10 元

  return $total;
}
?>
```

**常用的 WooCommerce _筛选_：**

以下是一些常用的 WooCommerce _筛选_，以及它们所触发的事件：

*   `woocommerce_checkout_order_process`:  在用户完成结账时触发。
*   `woocommerce_email_order_meta_fields`:  在发送订单邮件时，允许您添加自定义元数据字段。
*   `woocommerce_product_categories_tree_children_render`:  用于自定义产品分类树的渲染方式。
*   `woocommerce_product_thumbnail`:  用于修改产品缩略图。
*   `woocommerce_payment_complete`:  在支付完成后触发。

**更多信息：**

有关 WooCommerce _筛选_ 的更多信息，请参阅 WooCommerce 的官方文档：[https://woocommerce.com/document/developers/](https://woocommerce.com/document/developers/)

**重要提示：**

*   在使用 _筛选_ 时，请务必小心，并确保您的自定义代码不会影响 WooCommerce 的正常运行。
*   在修改任何 _筛选_ 之前，请务必备份您的网站。
*   如果您不确定如何使用 _筛选_，请咨询专业的 WooCommerce 开发人员。

**示例：修改产品价格**

以下示例展示了如何使用 `woocommerce_price` _筛选_ 来修改产品价格：

```php
<?php
add_filter( 'woocommerce_price', 'custom_product_price', 10, 2 );

function custom_product_price( $price, $product ) {
  // 仅对特定产品修改价格
  if ( $product->get_id() == 123 ) { // 假设产品 ID 为 123
    $price = $price * 0.9; // 降低 10%
  }

  return $price;
}
?>
```

**示例：修改产品描述**

以下示例展示了如何使用 `woocommerce_product_description` _筛选_ 来修改产品描述：

```php
<?php
add_filter( 'woocommerce_product_description', 'custom_product_description', 10, 1 );

function custom_product_description( $description ) {
  // 在产品描述的开头添加一段自定义文本
  $custom_text = '<p>这是一段自定义文本，将在产品描述的开头显示。</p>';

  return $custom_text . $description;
}
?>
```

**示例：修改产品图片大小**

以下示例展示了如何使用 `woocommerce_product_image_src` _筛选_ 来修改产品图片大小：

```php
<?php
add_filter( 'woocommerce_product_image_src', 'custom_product_image_size', 10, 3 );

function custom_product_image_size( $image_src, $size, $product ) {
  // 仅对特定产品修改图片大小
  if ( $product->get_id() == 456 ) { // 假设产品 ID 为 456
    $image_src = str_replace( array( 'woocommerce-small', 'woocommerce-medium', 'woocommerce-large' ), 'woocommerce-large', $image_src ); // 强制使用 large 尺寸
  }

  return $image_src;
}
?>
```

希望这些示例能够帮助您更好地理解如何使用 WooCommerce _筛选_。  请记住，在使用 _筛选_ 时，请务必小心

| Old hook | Works in blocks? | Notes |
| --- | --- | --- |
| `woocommerce_notice_types` | Unknown ❓ | WC Blocks does not handle additional notice types outside of the core ones. Non-supported notices would be displayed as "info" notices. |
| `woocommerce_kses_notice_allowed_tags` | Unknown ❓ | |
| `woocommerce_product_get_stock_status` | Fully supported ✅ | |
| `woocommerce_product_is_in_stock` | Fully supported ✅ | |
| `woocommerce_product_get_manage_stock` | Unknown ❓ | |
| `woocommerce_product_get_tax_class` | Fully supported ✅ | |
| `woocommerce_product_get_tax_status` | Unknown ❓ | |
| `woocommerce_prices_include_tax` | Unknown ❓ | |
| `woocommerce_apply_base_tax_for_local_pickup` | Unknown ❓ | |
| `woocommerce_local_pickup_methods` | Not supported ❌ | Does not affect the blocks-based local pickup methods |
| `woocommerce_customer_get_shipping_postcode` | Fully supported ✅ | |
| `woocommerce_customer_get_shipping_city` | Fully supported ✅ | |
| `woocommerce_customer_taxable_address` | Unknown ❓ | |
| `woocommerce_shipping_methods` | Fully supported ✅ | |
| `woocommerce_format_localized_price` | Unknown ❓ | |
| `woocommerce_shipping_local_pickup_option` | Not supported ❌ | Does not affect the blocks-based local pickup methods |
| `woocommerce_shipping_pickup_location_option` | Unknown ❓ | Unsure if changing this changes the way local pickup shows in the Cart/Checkout |
| `woocommerce_shipping_method_supports` | Fully supported ✅ | |
| `woocommerce_get_tax_location` | Unknown ❓ | |
| `woocommerce_format_postcode` | Unknown ❓ | |
| `woocommerce_matched_tax_rates` | Unknown ❓ | |
| `woocommerce_find_rates` | Unknown ❓ | |
| `woocommerce_matched_rates` | Unknown ❓ | |
| `woocommerce_cart_totals_get_item_tax_rates` | Fully supported ✅ | |
| `woocommerce_adjust_non_base_location_prices` | Unknown ❓ | |
| `woocommerce_product_is_taxable` | Fully supported ✅ | |
| `woocommerce_price_ex_tax_amount` | Fully supported ✅ | |
| `woocommerce_tax_round` | Fully supported ✅ | |
| `woocommerce_calc_tax` | Fully supported ✅ | |
| `woocommerce_calculate_item_totals_taxes` | Fully supported ✅ | |
| `woocommerce_cart_ready_to_calc_shipping` | Fully supported ✅ | |
| `woocommerce_product_get_virtual` | Fully supported ✅ | |
| `woocommerce_is_virtual` | Fully supported ✅ | |
| `woocommerce_product_needs_shipping` | Fully supported ✅ | |
| `woocommerce_cart_needs_shipping` | Fully supported ✅ | |
| `woocommerce_customer_get_shipping_address_1` | Fully supported ✅ | |
| `woocommerce_customer_get_shipping_address_2` | Fully supported ✅ | |
| `woocommerce_cart_display_prices_including_tax` | Fully supported ✅ | |
| `woocommerce_cart_get_subtotal` | Fully supported ✅ | |
| `woocommerce_cart_shipping_packages` | Fully supported ✅ | |
| `woocommerce_product_get_shipping_class_id` | Fully supported ✅ | |
| `woocommerce_countries_shipping_countries` | Fully supported ✅ | |
| `woocommerce_get_zone_criteria` | Fully supported ✅ | |
| `woocommerce_shipping_zone_shipping_methods` | Fully supported ✅ | |
| `woocommerce_shipping_free_shipping_is_available` | Unknown ❓ | |
| `woocommerce_product_get_name` | Fully supported ✅ | |
| `woocommerce_shipping_method_add_rate` | Fully supported ✅ | |
| `woocommerce_shipping_flat_rate_is_available` | Fully supported ✅ | |
| `woocommerce_evaluate_shipping_cost_args` | Fully supported ✅ | |
| `woocommerce_calc_shipping_tax` | Fully supported ✅ | |
| `woocommerce_localisation_address_formats` | Fully supported ✅ | |
| `woocommerce_countries_base_country` | Unknown ❓ | |
| `woocommerce_formatted_address_force_country_display` | Unknown ❓ | |
| `woocommerce_states` | Fully supported ✅ | |
| `woocommerce_formatted_address_replacements` | Unknown ❓ | |
| `woocommerce_package_rates` | Fully supported ✅ | |
| `woocommerce_shipping_packages` | Fully supported ✅ | |
| `woocommerce_shipping_rate_method_id` | Fully supported ✅ | |
| `woocommerce_shipping_rate_taxes` | Fully supported ✅ | |
| `woocommerce_shipping_rate_cost` | Fully supported ✅ | |
| `woocommerce_cart_totals_get_fees_from_cart_taxes` | Fully supported ✅ | |
| `woocommerce_calculated_total` | Not supported ❌ | This does not seem to have any effect |
| `woocommerce_cart_get_discount_total` | Fully supported ✅ | |
| `woocommerce_cart_get_cart_contents_total` | Fully supported ✅ | |
| `woocommerce_get_price_excluding_tax` | Not supported ❌ | This does not seem to have any effect |
| `raw_woocommerce_price` | Not supported ❌ | This does not seem to have any effect |
| `formatted_woocommerce_price` | Not supported ❌ | This does not seem to have any effect |
| `woocommerce_price_trim_zeros` | Not supported ❌ | This does not seem to have any effect |
| `woocommerce_get_cart_page_permalink` | Not supported ❌ | This does not seem to have any effect |
| `woocommerce_get_cart_url` | Not supported ❌ | This does not seem to have any effect |
| `woocommerce_checkout_registration_enabled` | Fully supported ✅ | This does not seem to have any effect |
| `woocommerce_get_checkout_page_permalink` | Not supported ❌ | This does not seem to have any effect |
| `woocommerce_get_checkout_url` | Not supported ❌ | This does not seem to have any effect |
| `woocommerce_checkout_get_value` | Not supported ❌ | This does not seem to have any effect |
| `woocommerce_default_address_fields` | Not supported ❌ | This does not seem to have any effect |
| `default_checkout_billing_country` | Not supported ❌ | This does not seem to have any effect |
| `default_checkout_shipping_country` | Not supported ❌ | This does not seem to have any effect |
| `woocommerce_get_country_locale` | Fully supported ✅ | |
| `woocommerce_get_country_locale_default` | Unknown ❓ | |
| `woocommerce_get_country_locale_base` | Unknown ❓ | |
| `woocommerce_billing_fields` | Partially supported 🔶 | Editing core fields is not supported, but adding them is via Additional Checkout Fields API |
| `woocommerce_shipping_fields` | Partially supported 🔶 | Editing core fields is not supported, but adding them is via Additional Checkout Fields API |
| `woocommerce_checkout_fields` | Partially supported 🔶 | Editing core fields is not supported, but adding them is via Additional Checkout Fields API |
| `woocommerce_cart_item_product` | Not supported ❌ | Modifying individual cart items is not possible |
| `woocommerce_payment_gateway_supports` | Fully supported ✅ | |
| `woocommerce_customer_get_billing_first_name` | Fully supported ✅ | |
| `woocommerce_customer_get_billing_last_name` | Fully supported ✅ | |
| `woocommerce_customer_get_billing_company` | Fully supported ✅ | |
| `woocommerce_customer_get_billing_address_1` | Fully supported ✅ | |
| `woocommerce_customer_get_billing_address_2` | Fully supported ✅ | |
| `woocommerce_customer_get_billing_city` | Fully supported ✅ | |
| `woocommerce_customer_get_billing_postcode` | Fully supported ✅ | |
| `woocommerce_customer_get_billing_phone` | Fully supported ✅ | |
| `woocommerce_customer_get_shipping_first_name` | Fully supported ✅ | |
| `woocommerce_customer_get_shipping_last_name` | Fully supported ✅ | |
| `woocommerce_customer_get_shipping_company` | Fully supported ✅ | |
| `woocommerce_get_item_data` | Partially supported 🔶 | Checkout blocks strip most HTML from metadata, allowing only a, b, em, i, strong, br, abbr, and span. |
| `woocommerce_cart_get_subtotal_tax` | Not supported ❌ | This does not seem to have any effect |
| `woocommerce_shipping_package_name` | Fully supported ✅ | |
| `woocommerce_shipping_rate_id` | Unknown ❓ | |
| `woocommerce_shipping_rate_label` | Fully supported ✅ | |
| `woocommerce_cart_get_shipping_taxes` | Fully supported ✅ | |
| `woocommerce_cart_get_fee_taxes` | Fully supported ✅ | |
| `woocommerce_cart_get_taxes` | Fully supported ✅ | |
| `woocommerce_rate_code` | Unknown ❓ | |
| `woocommerce_rate_compound` | Unknown ❓ | |
| `woocommerce_rate_label` | Fully supported ✅ | |
| `woocommerce_cart_hide_zero_taxes` | Unknown ❓ | |
| `woocommerce_cart_tax_totals` | Fully supported ✅ | |
| `woocommerce_cart_needs_payment` | Fully supported ✅ | |
| `woocommerce_order_class` | Fully supported ✅ | |
| `woocommerce_checkout_registration_required` | Unknown ❓ | |
| `woocommerce_privacy_policy_page_id` | Fully supported ✅ | |
| `woocommerce_get_terms_page_id` | Unknown ❓ | |
| `woocommerce_terms_and_conditions_page_id` | Unknown ❓ | |
| `woocommerce_cart_contents_count` | Unknown ❓ | |
| `woocommerce_country_locale_field_selectors` | Not supported ❌ | |
| `woocommerce_get_return_url` | Fully supported ✅ | |
| `woocommerce_cart_hash` | Fully supported ✅ | |
| `woocommerce_cart_get_fee_tax` | Fully supported ✅ | |
| `woocommerce_customer_default_location_array` | Fully supported ✅ | |
| `woocommerce_countries` | Fully supported ✅ | |
| `woocommerce_sort_countries` | Not supported ❌ | This does not seem to have any effect |
| `woocommerce_countries_allowed_countries` | Fully supported ✅ | |
| `woocommerce_customer_default_location_array` | Fully supported ✅ | |
| `woocommerce_customer_get_billing_country` | Fully supported ✅ | |
| `woocommerce_customer_get_shipping_country` | Fully supported ✅ | |
| `woocommerce_customer_get_billing_state` | Fully supported ✅ | |
| `woocommerce_customer_get_shipping_state` | Fully supported ✅ | |
| `woocommerce_customer_get_billing_email` | Fully supported ✅ | |
| `woocommerce_cart_session_initialize` | Fully supported ✅ | |
| `woocommerce_get_checkout_page_id` | Fully supported ✅ | |
| `woocommerce_get_cart_page_id` | Fully supported ✅ | |
| `woocommerce_is_checkout` | Fully supported ✅ | |
| `woocommerce_currency` | Fully supported ✅ | |
| `woocommerce_currency_symbols` | Fully supported ✅ | |
| `woocommerce_currency_symbol` | Fully supported ✅ | |
| `woocommerce_price_format` | Fully supported ✅ | |
| `woocommerce_coupons_enabled` | Fully supported ✅ | |
| `woocommerce_get_shop_page_id` | Fully supported ✅ | |
| `current_theme_supports-woocommerce` | Fully supported ✅ | |
| `woocommerce_payment_gateways` | Partially supported 🔶 | Integration with WC Blocks is still required, beyond unsetting gateways, manipulating the payment gateways here may not work in the Cart and Checkout blocks |
| `woocommerce_get_base_location` | Fully supported ✅ | |
| `woocommerce_gateway_icon` | Not supported ❌ | This hook has no effect since icons are not displayed. |
| `woocommerce_get_image_size_thumbnail` | Fully supported ✅ | |
| `woocommerce_get_image_size_single` | Fully supported ✅ | |
| `woocommerce_product_stock_status_options` | Fully supported ✅ | |
| `woocommerce_cart_item_name` | Not supported ❌ | Use the [`itemName` checkout filter](https://developer.woocommerce.com/docs/cart-and-checkout-filters-cart-line-items/#2-itemname). |
| `woocommerce_product_get_status` | Fully supported ✅ | |
| `woocommerce_product_get_price` | Fully supported ✅ | |
| `woocommerce_is_purchasable` | Fully supported ✅ | |
| `woocommerce_cart_item_is_purchasable` | Fully supported ✅ | |
| `woocommerce_cart_item_data_to_validate` | Fully supported ✅ | |
| `woocommerce_get_cart_item_from_session` | Fully supported ✅ | |
| `woocommerce_cart_contents_changed` | Fully supported ✅ | |
| `woocommerce_get_cart_contents` | Fully supported ✅ | |
| `woocommerce_stock_amount` | Fully supported ✅ | |
| `woocommerce_cart_item_remove_link` | Not supported ❌ | Use the [`showRemoveItemLink` checkout filter](https://developer.woocommerce.com/docs/cart-and-checkout-filters-cart-line-items/#4-showremoveitemlink). |
| `woocommerce_cart_item_quantity` | Not supported ❌ | This is possible by modifying the quantity_limits property of the cart item in the `woocommerce_store_api_product_quantity_{$value_type}` filter. |
| `woocommerce_product_get_image` | Not supported ❌ | Use `woocommerce_store_api_cart_item_images` ([PR Link](https://github.com/woocommerce/woocommerce/pull/52310) with example.) |
| `woocommerce_cart_no_shipping_available_html` | Not supported ❌ | This is not editable |
| `woocommerce_available_payment_gateways` | Partially supported 🔶 | Integration with WC Blocks is still required, beyond unsetting gateways, manipulating the payment gateways here may not work in the Cart and Checkout blocks |
| `woocommerce_cart_get_total` | Fully supported ✅ | |
| `woocommerce_cart_get_fee_tax` | Fully supported ✅ | |
| `woocommerce_cart_get_cart_contents_tax` | Fully supported ✅ | |
| `woocommerce_cart_get_shipping_tax` | Fully supported ✅ | |
| `woocommerce_cart_get_shipping_total` | Fully supported ✅ | |

### 购物车 _操作_

**Add item to cart**

将商品添加到购物车。

**View cart**

查看购物车。

**Remove item from cart**

从购物车中移除商品。

**Update item quantity in cart**

更新购物车中商品的数量。

**Clear cart**

清空购物车。

**Checkout**

结账。

**Example:**

```
// Example code
function addItemToCart(item) {
  // Add item to the cart
}
```

**Explanation:**

*   `AddItemToCart` 操作用于将商品添加到购物车。
*   `ViewCart` 操作用于查看购物车中的商品。
*   `RemoveItemFromCart` 操作用于从购物车中移除商品。
*   `UpdateItemQuantityInCart` 操作用于更新购物车中商品的数量。
*   `ClearCart` 操作用于清空购物车。
*   `Checkout` 操作用于完成购买流程。

**Note:**

*   `%s` 是一个占位符，可以替换为任何字符串。
*   `%d` 是一个占位符，可以替换为任何整数。
*   `{name}` 是一个占位符，可以替换为任何名称。
*   `on` 表示设备或功能处于开启状态。

规则:
1. 翻译所有英文文本，包括标题、段落、列表项
2. 保持 Markdown 格式不变（#、**、``、[]() 等）
3. 代码块（```...```）内的代码不翻译，只翻译代码块外的文本
4. 保留所有占位符（%s, %d, {name}）和 HTML 标签
5. 保留所有 URL 链接地址不翻译
6. 函数名、变量名、命令名保留英文原文
7. 只输出翻译结果，不要输出解释或原文

术语表（必须使用以下译法）:
- Available → 可用
- Discount → 折扣
- Position → 位置
- Quantity → 数量
- Contents → 内容
- manually → 手动
- Shipping → 配送
- Checkout → 结账
- Actions → 操作
- Orders → 订单
- Button → 按钮
- Before → 前
- Manual → 手册
- Coupon → 优惠券
- Hooks → 钩子
- Close → 关闭
- Field → 字段
- After → 后
- Input → 输入
- check → 检查

| Old hook | Works in blocks? | Notes |
| --- | --- | --- |
| `woocommerce_before_cart` | Not supported ❌ | 没有特定的等效项，也没有可用的 Slot/fill 位置。 也许向 "购物车商品" 块添加一个内部块可以实现，但必须由商家手动进行位置调整。 也可以使用 [`render_block_{$name}`](https://developer.wordpress.org/reference/hooks/render_block_this-name/) 过滤器，通过 PHP 在前后添加块。 |
| `woocommerce_before_cart_table` | Not supported ❌ | 没有特定的等效项，也没有可用的 Slot/fill 位置。 也许向 "购物车商品" 块添加一个内部块可以实现，但必须由商家手动进行位置调整。 |
| `woocommerce_before_cart_contents` | Not supported ❌ | 没有特定的等效项，也没有可用的 Slot/fill 位置。 也许向 "购物车商品" 块添加一个内部块可以实现，但必须由商家手动进行位置调整。 |
| `woocommerce_after_cart_item_name` | Not supported ❌ | 使用 [`itemName` 结账过滤器](https://developer.woocommerce.com/docs/cart-and-checkout-filters-cart-line-items/#2-itemname)。 |
| `woocommerce_before_quantity_input_field` | Not supported ❌ | 目前没有等效项。 |
| `woocommerce_after_quantity_input_field` | Not supported ❌ | 目前没有等效项。 |
| `woocommerce_cart_contents` | Not supported ❌ | 没有特定的等效项，也没有可用的 Slot/fill 位置。 也许向 "购物车商品" 块添加一个内部块可以实现，但必须由商家手动进行位置调整。 |
| `woocommerce_cart_coupon` | Not supported ❌ | [`ExperimentalDiscountsMeta` slot/fill](https://developer.woocommerce.com/docs/cart-and-checkout-available-slots/#3-experimentaldiscountsmeta) |
| `woocommerce_cart_actions` | Not supported ❌ | [`ExperimentalOrderMeta` slot/fill](https://developer.woocommerce.com/docs/cart-and-checkout-available-slots/#0-experimentalordermeta) |
| `woocommerce_after_cart_contents` | Not supported ❌ | 没有特定的等效项，也没有可用的 Slot/fill 位置。 也许向 "购物车商品" 块添加一个内部块可以实现，但必须由商家手动进行位置调整。 |
| `woocommerce_after_cart_table` | Not supported ❌ | 没有特定的等效项，也没有可用的 Slot/fill 位置。 也许向 "购物车商品" 块添加一个内部块可以实现，但必须由商家手动进行位置调整。 |
| `woocommerce_before_cart_collaterals` | Not supported ❌ | 没有特定的等效项，也没有可用的 Slot/fill 位置。 也许向 "购物车商品" 块添加一个内部块可以实现，但必须由商家手动进行位置调整。 |
| `woocommerce_cart_collaterals` | Not supported ❌ | 没有特定的等效项，也没有可用的 Slot/fill 位置。 也许向 "购物车商品" 块添加一个内部块可以实现，但必须由商家手动进行位置调整。 |
| `woocommerce_before_cart_totals` | Not supported ❌ | [`ExperimentalOrderMeta` slot/fill](https://developer.woocommerce.com/docs/cart-and-checkout-available-slots/#0-experimentalordermeta) |
| `woocommerce_cart_totals_before_shipping` | Not supported ❌ | [ExperimentalOrderShippingPackages](https://developer.woocommerce.com/docs/cart-and-checkout-available-slots/#1-experimentalordershippingpackages) |
| `woocommerce_after_shipping_rate` | Not supported ❌ | [ExperimentalOrderShippingPackages](https://developer.woocommerce.com/docs/cart-and-checkout-available-slots/#1-experimentalordershippingpackages) |
| `woocommerce_before_shipping_calculator` | Not supported ❌ | 没有特定的等效项。 最接近的是 ExperimentalOrderShippingPackages |
| `woocommerce_after_shipping_calculator` | Not supported ❌ | 没有特定的等效项。 最接近的是 ExperimentalOrderShippingPackages |
| `woocommerce_cart_totals_after_shipping` | Not supported ❌ | 没有特定的等效项。 最接近的是 ExperimentalOrderShippingPackages |
| `woocommerce_cart_totals_before_order_total` | Not supported ❌ | 没有特定的等效项，但我们有总价部分的过滤器。 |
| `woocommerce_cart_totals_after_order_total` | Not supported ❌ | 没有特定的等效项，但我们有总价部分的过滤器。 |
| `woocommerce_proceed_to_checkout` | Not supported ❌ | 没有特定的等效项，但结账和“提交订单”按钮的过滤器可能有效。 |
| `woocommerce_after_cart_totals` | Not supported ❌ | [`ExperimentalOrderMeta` slot/fill](https://developer.woocommerce.com/docs/cart-and-checkout-available-slots/#0-experimentalordermeta) |
| `woocommerce_after_cart` | Not supported ❌ | 没有特定的等效项，也没有可用的 Slot/fill 位置。 也许向 "购物车商品" 块添加一个内部块可以实现，但必须由商家手动进行位置调整。 |

### 购物车 _筛选_

本节描述如何使用 _筛选_ 功能来管理购物车中的商品。

**购物车筛选功能**

购物车筛选功能允许用户根据各种条件过滤购物车中的商品，例如：

*   **商品类型:**  可以根据商品类型进行筛选，例如：服装、电子产品、书籍等。
*   **价格范围:**  可以根据价格范围进行筛选，例如：低于 100 元、100-200 元、高于 200 元等。
*   **品牌:**  可以根据品牌进行筛选，例如：Nike、Adidas、Apple 等。
*   **库存:**  可以根据库存数量进行筛选，例如：仅显示有库存的商品。

**使用方法**

要使用购物车筛选功能，请按照以下步骤操作：

1.  打开购物车页面。
2.  点击“筛选”按钮。
3.  在弹出的筛选窗口中，选择要应用的筛选条件。
4.  点击“应用”按钮。

**示例**

以下是一个使用购物车筛选功能的示例：

假设您想筛选购物车中所有价格低于 100 元的服装商品。

1.  打开购物车页面。
2.  点击“筛选”按钮。
3.  在筛选窗口中，选择“商品类型”为“服装”，并选择“价格范围”为“低于 100 元”。
4.  点击“应用”按钮。

购物车页面将只显示价格低于 100 元的服装商品。

**高级用法**

购物车筛选功能还支持一些高级用法，例如：

*   **多条件筛选:**  可以同时应用多个筛选条件。
*   **自定义筛选条件:**  可以根据需要自定义筛选条件。

有关高级用法的更多信息，请参考相关文档。

**代码示例**

以下是一个使用 Python 语言实现购物车筛选功能的示例代码：

```python
def filter_cart(cart, filters):
  """
  Filters a cart based on the given filters.

  Args:
    cart: A list of items in the cart.
    filters: A dictionary of filters.

  Returns:
    A list of items in the cart that match the filters.
  """
  filtered_cart = []
  for item in cart:
    match = True
    for key, value in filters.items():
      if key == "type" and item["type"] != value:
        match = False
      elif key == "price" and item["price"] > value:
        match = False
    if match:
      filtered_cart.append(item)
  return filtered_cart

# Example usage
cart = [
  {"name": "T-shirt", "type": "clothing", "price": 20},
  {"name": "Jeans", "type": "clothing", "price": 50},
  {"name": "Laptop", "type": "electronics", "price": 1000},
]

filters = {"type": "clothing", "price": 50}

filtered_cart = filter_cart(cart, filters)

print(filtered_cart)
```

**错误处理**

如果在应用筛选功能时出现错误，请检查以下事项：

*   确保已正确配置筛选条件。
*   确保购物车中存在符合筛选条件的商品。
*   如果问题仍然存在，请联系技术支持。

**相关链接**

*   [购物车管理](link_to_cart_management)
*   [筛选功能详解](link_to_filter_details)
*   [常见问题](link_to_faq)

希望本节内容对您有所帮助。如有任何疑问，请随时联系我们。

# 规则说明

本文档提供了关于 WooCommerce 块的 `Hook` 支持情况说明。

| 旧的 `Hook` | 是否支持块？ | 备注 |
|---|---|---|
| `woocommerce_cart_item_product_id` | 不支持 ❌ | 似乎没有任何效果。 |
| `woocommerce_cart_item_visible` | 不支持 ❌ | 似乎没有任何效果。 |
| `woocommerce_get_remove_url` | 不支持 ❌ | 购物车块中的商品移除操作是异步处理的。 |
| `woocommerce_cart_item_remove_link` | 不支持 ❌ | 购物车块中的商品移除操作是异步处理的。 |
| `woocommerce_cart_item_thumbnail` | 不支持 ❌ | 这种方式修改缩略图不受支持。 请参阅 `woocommerce_store_api_cart_item_images` ([PR Link](https://github.com/woocommerce/woocommerce/pull/52310) 附带示例)。 |
| `woocommerce_cart_product_price` | 不支持 ❌ |  |
| `woocommerce_cart_item_price` | 不支持 ❌ |  |
| `woocommerce_quantity_input_classes` | 不支持 ❌ |  |
| `woocommerce_quantity_input_max` | 不支持 ❌ | 可以通过修改购物车项的 `quantity_limits` 属性，在 `woocommerce_store_api_product_quantity_{$value_type}` 过滤器中实现。 |
| `woocommerce_quantity_input_min` | 不支持 ❌ | 可以通过修改购物车项的 `quantity_limits` 属性，在 `woocommerce_store_api_product_quantity_{$value_type}` 过滤器中实现。 |
| `woocommerce_quantity_input_step` | 不支持 ❌ | 可以通过修改购物车项的 `quantity_limits` 属性，在 `woocommerce_store_api_product_quantity_{$value_type}` 过滤器中实现。 |
| `woocommerce_quantity_input_pattern` | 不支持 ❌ | 可以通过修改购物车项的 `quantity_limits` 属性，在 `woocommerce_store_api_product_quantity_{$value_type}` 过滤器中实现。 |
| `woocommerce_quantity_input_inputmode` | 不支持 ❌ | 可以通过修改购物车项的 `quantity_limits` 属性，在 `woocommerce_store_api_product_quantity_{$value_type}` 过滤器中实现。 |
| `woocommerce_quantity_input_placeholder` | 不支持 ❌ | 可以通过修改购物车项的 `quantity_limits` 属性，在 `woocommerce_store_api_product_quantity_{$value_type}` 过滤器中实现。 |
| `woocommerce_quantity_input_autocomplete` | 不支持 ❌ | 可以通过修改购物车项的 `quantity_limits` 属性，在 `woocommerce_store_api_product_quantity_{$value_type}` 过滤器中实现。 |
| `woocommerce_quantity_input_args` | 不支持 ❌ | 可以通过修改购物车项的 `quantity_limits` 属性，在 `woocommerce_store_api_product_quantity_{$value_type}` 过滤器中实现。 |
| `woocommerce_quantity_input_type` | 不支持 ❌ | 可以通过修改购物车项的 `quantity_limits` 属性，在 `woocommerce_store_api_product_quantity_{$value_type}` 过滤器中实现。 |
| `woocommerce_cart_item_quantity` | 不支持 ❌ | 可以通过修改购物车项的 `quantity_limits` 属性，在 `woocommerce_store_api_product_quantity_{$value_type}` 过滤器中实现。 |
| `woocommerce_cart_product_subtotal` | 不支持 ❌ |  |
| `woocommerce_cart_item_subtotal` | 不支持 ❌ |  |
| `woocommerce_cross_sells_columns` | 不支持 ❌ | 推荐商品以内部块的形式呈现。 |
| `woocommerce_cross_sells_orderby` | 不支持 ❌ | 推荐商品以内部块的形式呈现。 |
| `woocommerce_cross_sells_order` | 不支持 ❌ | 推荐商品以内部块的形式呈现。 |
| `woocommerce_cross_sells_total` | 不支持 ❌ | 推荐商品以内部块的形式呈现。 |
| `woocommerce_product_cross_sells_products_heading` | 不支持 ❌ | 可以在编辑器中进行修改。 |
| `woocommerce_is_downloadable` | 不支持 ❌ | 在购物车/结账块中似乎没有任何效果。 |
| `woocommerce_loop_product_link` | 不支持 ❌ | 在购物车块中，修改产品链接不受支持。 |
| `woocommerce_product_loop_title_classes` | 不支持 ❌ | 在购物车块中，修改产品标题的类名不受支持。 |
| `woocommerce_product_add_to_cart_aria_describedby` | 不支持 ❌ | 在购物车块中，修改产品 `aria-describedby` 属性不受支持。 |
| `woocommerce_sale_flash` | 不支持 ❌ | 可以使用 [`saleBadgePriceFormat` 结账过滤器](https://developer.woocommerce.com/docs/cart-and-checkout-filters-cart-line-items/#3-salebadgepriceformat) 进行修改。 |
| `woocommerce_cart_subtotal` | 不支持 ❌ | 在购物车/结账块中，修改购物车小计的显示不受支持。 |
| `oocommerce_shipping_package_details_array` | 不支持 ❌ | 此 `Hook` 在购物车块渲染过程中不会被触发。 |
| `woocommerce_shipping_show_shipping_calculator` | 不支持 ❌ | 仅在渲染购物车模板时使用，而块不使用模板。 |
| `woocommerce_cart_shipping_method_full_label` | 不支持 ❌ | 此 `Hook` 在购物车/结账块中无效。 |
| `woocommerce_get_shipping_tax` | 不支持 ❌ | 此过滤器在购物车/结账块中未使用。 |
| `woocommerce_shipping_calculator_enable_country` | 不支持 ❌ | 此过滤器在购物车/结账块中未使用。 |
| `woocommerce_shipping_calculator_enable_state` | 不支持 ❌ | 此过滤器在购物车/结账块中未使用。 |
| `woocommerce_shipping_calculator_enable_city` | 不支持 ❌ | 此过滤器在购物车/结账块中未使用。 |
| `woocommerce_shipping_calculator_enable_postcode` | 不支持 ❌ | 此过滤器在购物车/结账块中未使用。 |
| `woocommerce_cart_totals_fee_html` | 不支持 ❌ | 在购物车/结账块中，修改费用显示不受支持。 |
| `woocommerce_countries_estimated_for_prefix` | 不支持 ❌ |  |
| `woocommerce_cart_total` | 不支持 ❌ | 在购物车/结账块中，使用此 `Hook` 修改购物车总额不受支持。 |
| `woocommerce_cart_totals_order_total_html` | 不支持 ❌ | 在购物车/结账块中，使用此 `Hook` 修改购物车总额不受支持。 |

**术语表:**

*   **Link**: 链接
*   **Hook**: 钩子
*   **API**: API
*   **Placeholder**: 占位符
*   **Rendering**: 渲染
*   **Templates**: 模板
*   **Download**: 下载
*   **Quantity**: 数量
*   **Subtotal**: 小计
*   **Property**: 属性
*   **Shipping**: 配送
*   **Checkout**: 结账
*   **Details**: 详情
*   **Display**: 显示
*   **Heading**: 标题
*   **Product**: 产品
*   **Enable**: 启用
*   **Remove**: 移除
*   **Images**: 图像
*   **Format**: 格式

### 结账 _操作_

本节描述与结账相关的操作。

**重要提示：** 在执行以下操作之前，请确保您已正确配置您的 Git 环境。

以下是一些常见的结账操作：

*   **`git checkout <commit>`**:  切换到指定的提交。
*   **`git checkout <branch>`**: 切换到指定的分支。
*   **`git checkout -b <new_branch>`**: 创建一个新的分支并切换到该分支。
*   **`git checkout -- <file>`**:  取消对指定文件的修改，恢复到暂存区或 HEAD 的版本。
*   **`git checkout .`**: 取消所有文件的修改，恢复到暂存区或 HEAD 的版本。

**示例：**

```bash
git checkout commit_id
```

**说明：**

*   `<commit>`:  要切换到的提交的哈希值或引用。
*   `<branch>`:  要切换到的分支的名称。
*   `<new_branch>`:  要创建的新分支的名称。
*   `<file>`:  要取消修改的文件名。

**警告：**

*   结账操作可能会覆盖您本地的未提交更改。 在执行结账操作之前，请务必备份您的工作。
*   如果您的工作目录中有未提交的更改，并且您尝试切换到另一个分支，Git 可能会阻止您。 您可以使用 `git stash` 命令来暂存您的更改，然后执行结账操作。

**更多信息：**

有关 `git checkout` 命令的更多信息，请参阅 `git help checkout`。

**`git checkout` 命令的常用选项：**

*   `-n` 或 `--no-ornament`：不要在输出中显示装饰。
*   `--detach`：创建一个新的分支，但不要自动切换到该分支。
*   `-f` 或 `--force`：强制执行结账操作，即使存在冲突。

**`git checkout` 命令的常见错误：**

*   `error: Your local changes to the following files would be overwritten by checkout:`： 您的本地更改会覆盖以下文件。
*   `error: Could not checkout '<branch>'.  Branch '<branch>' does not exist.`： 无法切换到 '<branch>'。 分支 '<branch>' 不存在。

**`git checkout` 命令的替代方案：**

*   `git switch`：一个更现代的切换分支的命令。
*   `git reset`：一个用于重置工作目录和暂存区的命令。

**总结：**

`git checkout` 是一个强大的命令，可以用于在不同的提交、分支和工作目录状态之间进行切换。 但是，在使用 `git checkout` 命令时，请务必小心，因为它可能会覆盖您本地的未提交更改。

# 钩子兼容性列表

本表列出了 WooCommerce 钩子及其在 Cart/Checkout 块中的兼容性。

| 旧钩子 | 是否支持块？ | 备注 |
|---|---|---|
| `woocommerce_before_checkout_form_cart_notices` | 不支持 ❌ | 没有直接对应的功能，也没有可用的 Slot/fill 区域。 也许可以在 "结账字段" 块中添加一个内部块来实现，但位置需要由商家手动调整。 |
| `woocommerce_before_checkout_form` | 不支持 ❌ | 没有直接对应的功能，也没有可用的 Slot/fill 区域。 也许可以在 "结账字段" 块中添加一个内部块来实现，但位置需要由商家手动调整。 |
| `woocommerce_checkout_before_customer_details` | 不支持 ❌ | 没有直接对应的功能，也没有可用的 Slot/fill 区域。 也许可以在 "结账字段" 块中添加一个内部块来实现，但位置需要由商家手动调整。 |
| `woocommerce_checkout_billing` | 不支持 ❌ | 没有直接对应的功能，也没有可用的 Slot/fill 区域。 也许可以在 "结账字段" 块中添加一个内部块来实现，但位置需要由商家手动调整。 |
| `woocommerce_before_checkout_billing_form` | 不支持 ❌ | 没有直接对应的功能，也没有可用的 Slot/fill 区域。 也许可以在 "结账字段" 块中添加一个内部块来实现，但位置需要由商家手动调整。 |
| `woocommerce_after_checkout_billing_form` | 不支持 ❌ | 没有直接对应的功能，也没有可用的 Slot/fill 区域。 也许可以在 "结账字段" 块中添加一个内部块来实现，但位置需要由商家手动调整。 |
| `woocommerce_checkout_shipping` | 不支持 ❌ | 由于位置限制，没有直接对应的功能，但是 [ExperimentalOrderShippingPackages](https://developer.woocommerce.com/docs/cart-and-checkout-available-slots/#1-experimentalordershippingpackages) 也许可以实现，或者可以在 "配送" 块中添加一个内部块。 |
| `woocommerce_before_checkout_shipping_form` | 不支持 ❌ | 由于位置限制，没有直接对应的功能，但是 [ExperimentalOrderShippingPackages](https://developer.woocommerce.com/docs/cart-and-checkout-available-slots/#1-experimentalordershippingpackages) 也许可以实现，或者可以在 "配送" 块中添加一个内部块。 |
| `woocommerce_after_checkout_shipping_form` | 不支持 ❌ | 由于位置限制，没有直接对应的功能，但是 [ExperimentalOrderShippingPackages](https://developer.woocommerce.com/docs/cart-and-checkout-available-slots/#1-experimentalordershippingpackages) 也许可以实现，或者可以在 "配送" 块中添加一个内部块。 |
| `woocommerce_before_order_notes` | 不支持 ❌ | 没有直接对应的功能，也没有可用的 Slot/fill 区域。 也许可以在 "结账字段" 块中添加一个内部块来实现，但位置需要由商家手动调整。 |
| `woocommerce_after_order_notes` | 不支持 ❌ | 没有直接对应的功能，也没有可用的 Slot/fill 区域。 也许可以在 "结账字段" 块中添加一个内部块来实现，但位置需要由商家手动调整。 |
| `woocommerce_checkout_after_customer_details` | 不支持 ❌ | 没有直接对应的功能，也没有可用的 Slot/fill 区域。 也许可以在 "结账字段" 块中添加一个内部块来实现，但位置需要由商家手动调整。 |
| `woocommerce_checkout_before_order_review_heading` | 不支持 ❌ | 没有直接对应的功能，也没有可用的 Slot/fill 区域。 也许可以在 "结账订单摘要" 块中添加一个内部块来实现，但位置需要由商家手动调整。 |
| `woocommerce_checkout_before_order_review` | 不支持 ❌ | 没有直接对应的功能，也没有可用的 Slot/fill 区域。 也许可以在 "结账订单摘要" 块中添加一个内部块来实现，但位置需要由商家手动调整。 |
| `woocommerce_checkout_order_review` | 不支持 ❌ | 没有直接对应的功能，也没有可用的 Slot/fill 区域。 也许可以在 "结账订单摘要" 块中添加一个内部块来实现，但位置需要由商家手动调整。 |
| `woocommerce_review_order_before_cart_contents` | 不支持 ❌ | 没有直接对应的功能，也没有可用的 Slot/fill 区域。 也许可以在 "结账订单摘要" 块中添加一个内部块来实现，但位置需要由商家手动调整。 |
| `woocommerce_review_order_after_cart_contents` | 不支持 ❌ | 没有直接对应的功能，也没有可用的 Slot/fill 区域。 也许可以在 "结账订单摘要" 块中添加一个内部块来实现，但位置需要由商家手动调整。 |
| `woocommerce_review_order_before_shipping` | 不支持 ❌ | 没有直接对应的功能，也没有可用的 Slot/fill 区域。 也许可以在 "结账订单摘要" 块中添加一个内部块来实现，但位置需要由商家手动调整。 |
| `woocommerce_after_shipping_rate` | 不支持 ❌ | 没有直接对应的功能，也没有可用的 Slot/fill 区域。 也许可以在 "结账订单摘要" 块中添加一个内部块来实现，但位置需要由商家手动调整。 |
| `woocommerce_review_order_after_shipping` | 不支持 ❌ | 没有直接对应的功能，也没有可用的 Slot/fill 区域。 也许可以在 "结账订单摘要" 块中添加一个内部块来实现，但位置需要由商家手动调整。 |
| `woocommerce_review_order_before_order_total` | 不支持 ❌ | 没有直接对应的功能，也没有可用的 Slot/fill 区域。 也许可以在 "结账订单摘要" 块中添加一个内部块来实现，但位置需要由商家手动调整。 |
| `woocommerce_review_order_after_order_total` | 不支持 ❌ | 没有直接对应的功能，也没有可用的 Slot/fill 区域。 也许可以在 "结账订单摘要" 块中添加一个内部块来实现，但位置需要由商家手动调整。 |
| `woocommerce_review_order_before_payment` | 不支持 ❌ | 没有直接对应的功能，也没有可用的 Slot/fill 区域。 也许可以在 "结账字段" 块或 "支付" 块中添加一个内部块来实现，但位置需要由商家手动调整。 |
| `woocommerce_checkout_before_terms_and_conditions` | 不支持 ❌ | 没有直接对应的功能，也没有可用的 Slot/fill 区域。 也许可以在 "结账字段" 块中添加一个内部块来实现，但位置需要由商家手动调整。 |
| `woocommerce_checkout_terms_and_conditions` | 不支持 ❌ | 没有直接对应的功能，也没有可用的 Slot/fill 区域。 也许可以在 "结账字段" 块中添加一个内部块来实现，但位置需要由商家手动调整。 |
| `woocommerce_checkout_after_terms_and_conditions` | 不支持 ❌ | 没有直接对应的功能，也没有可用的 Slot/fill 区域。 也许可以在 "结账字段" 块中添加一个内部块来实现，但位置需要由商家手动调整。 |
| `woocommerce_review_order_before_submit` | 不支持 ❌ | 没有直接对应的功能，也没有可用的 Slot/fill 区域。 也许可以在 "结账字段" 块中添加一个内部块来实现，但位置需要由商家手动调整。 |
| `woocommerce_review_order_after_submit` | 不支持 ❌ | 没有直接对应的功能，也没有可用的 Slot/fill 区域。 也许可以在 "结账字段" 块中添加一个内部块来实现，但位置需要由商家手动调整。 |
| `woocommerce_review_order_after_payment` | 不支持 ❌ | 没有直接对应的功能，也没有可用的 Slot/fill 区域。 也许可以在 "结账字段" 块或 "支付" 块中添加一个内部块来实现，但位置需要由商家手动调整。 |
| `woocommerce_checkout_after_order_review` | 不支持 ❌ | 没有直接对应的功能，也没有可用的 Slot/fill 区域。 也许可以在 "结账订单摘要" 块中添加一个内部块来实现，但位置需要由商家手动调整。 |
| `woocommerce_after_checkout_form` | 不支持 ❌ | 没有直接对应的功能，也没有可用的 Slot/fill 区域。 也许可以在 "结账字段" 块中添加一个内部块来实现，但位置需要由商家手动调整。 |
| `woocommerce_checkout_update_order_review` | 不支持 ❌ | 此类 AJAX 事件在使用 Cart/Checkout 块时不会发生。 |

### 结账 _筛选器_

本节描述如何使用 _筛选器_ 进行结账操作。

**重要提示:** 确保已正确配置您的系统，以便支持 _筛选器_。

以下是一些常见的结账流程：

1.  **准备商品:** 确保所有需要结账的商品已添加到购物车。
2.  **应用筛选器:** 使用 `apply_filter()` 函数应用所需的 _筛选器_。例如：

    ```python
    def apply_filter(filter_name, data):
        # 应用筛选器逻辑
        return data
    ```

3.  **计算总价:** 使用 `calculate_total()` 函数计算最终价格。

    ```python
    def calculate_total(items, discounts):
        # 计算总价逻辑
        return total_price
    ```

4.  **确认订单:** 确认订单信息，包括商品列表、总价和收货地址。
5.  **支付:** 选择支付方式并完成支付。
6.  **结账:** 完成结账流程。

**示例:**

```
# 示例代码
items = [
    {"name": "商品A", "price": 10},
    {"name": "商品B", "price": 20}
]
discounts = [
    {"type": "优惠券", "amount": 5}
]

total_price = calculate_total(items, discounts)
print(f"总价: {total_price}")
```

**常见问题:**

*   **如何添加新的 _筛选器_？**  请参考 _筛选器_ 开发文档。
*   **为什么我的 _筛选器_ 没有生效？**  请检查 _筛选器_ 的配置是否正确，以及是否已正确应用。
*   **如何调试 _筛选器_？**  可以使用 `debug_filter()` 函数进行调试。

**更多信息:**

*   [关于 _筛选器_ 的详细说明](https://example.com/filters)
*   [常见 _筛选器_ 示例](https://example.com/filter_examples)

请使用 `check` 功能检查系统状态。

# 钩子支持状态

| 旧钩子 | 是否支持块？ | 备注 |
|---|---|---|
| `woocommerce_add_notice` | 部分支持 🔶 | 这些通知仅在“购物车”/“结账”块的页面加载时添加。如果在 API 请求期间发生的通知会被存储并在下一次完整的页面加载时显示。 |
| `woocommerce_checkout_coupon_message` | 不支持 ❌ | 无法使用此过滤器自定义优惠券消息。 |
| `woocommerce_form_field_args` | 不支持 ❌ | 尚未支持修改核心表单字段。 |
| `woocommerce_form_field_text` | 不支持 ❌ | 尚未支持修改核心表单字段。 |
| `woocommerce_form_field` | 不支持 ❌ | 尚未支持修改核心表单字段。 |
| `woocommerce_form_field_country` | 不支持 ❌ | 尚未支持修改核心表单字段。 |
| `woocommerce_form_field_state` | 不支持 ❌ | 尚未支持修改核心表单字段。 |
| `woocommerce_form_field_tel` | 不支持 ❌ | 尚未支持修改核心表单字段。 |
| `woocommerce_form_field_email` | 不支持 ❌ | 尚未支持修改核心表单字段。 |
| `woocommerce_cart_needs_shipping_address` | 不支持 ❌ | 应使用 [`wc/store/cart` 数据存储](../data-store/cart.md) 来控制此项。 |
| `woocommerce_ship_to_different_address_checked` | 不支持 ❌ | 应使用 [`wc/store/checkout` 数据存储](../data-store/checkout.md) 来检查是否勾选了此复选框。 |
| `woocommerce_enable_order_notes_field` | 不支持 ❌ | 此块必须在编辑器中删除，此过滤器不会影响其在“结账”块中的显示。 |
| `woocommerce_form_field_textarea` | 不支持 ❌ | 尚未支持修改核心表单字段。 |
| `woocommerce_checkout_cart_item_visible` | 不支持 ❌ | 无法从“购物车”/“结账”块的订单摘要中过滤购物车项目。 |
| `woocommerce_cart_item_class` | 不支持 ❌ | 无法向“购物车”/“结账”块的订单摘要中的特定购物车项目添加类。 |
| `woocommerce_checkout_cart_item_quantity` | 不支持 ❌ | 无法修改“购物车”/“结账”块的订单摘要中购物车项目的数量显示。 |
| `woocommerce_cart_product_subtotal` | 不支持 ❌ | 不支持在“购物车”/“结账”块中修改产品小计的显示。 |
| `woocommerce_cart_item_subtotal` | 不支持 ❌ | 不支持在“购物车”/“结账”块中修改产品小计的显示。 |
| `woocommerce_cart_subtotal` | 不支持 ❌ | 不支持在“购物车”/“结账”块中修改购物车小计的显示。 |
| `woocommerce_cart_shipping_method_full_label` | 不支持 ❌ | 不支持在“购物车”/“结账”块中修改配送方式的显示。 |
| `woocommerce_get_shipping_tax` | 不支持 ❌ | 此过滤器不用于“购物车”/“结账”块。 |
| `woocommerce_cart_totals_fee_html` | 不支持 ❌ | 不支持在“购物车”/“结账”块中修改费用显示。 |
| `woocommerce_cart_total` | 不支持 ❌ | 不支持使用此钩子修改“购物车”/“结账”块中的购物车总计。 |
| `woocommerce_cart_totals_order_total_html` | 不支持 ❌ | 不支持使用此钩子修改“购物车”/“结账”块中的订单总计 HTML - 请在编辑器中进行修改。 |
| `woocommerce_order_button_text` | 不支持 ❌ | 不支持使用此钩子修改“购物车”/“结账”块中的订单按钮 HTML - 请在编辑器中进行修改。 |
| `woocommerce_gateway_title` | 不支持 ❌ | 这些内容可以包含在与“购物车”/“结账”块注册的网关渲染的“内容”中，但无法通过 PHP 过滤器控制此项。 |
| `woocommerce_gateway_icon` | 不支持 ❌ | 不显示网关图标。 它们可以包含在与“购物车”/“结账”块注册的网关渲染的“内容”中，但无法通过 PHP 过滤器控制此项。 |
| `woocommerce_gateway_description` | 不支持 ❌ | 无法通过这种方式更改网关，网关需要使用 JavaScript 与“购物车”/“结账”块注册，并且第三方扩展无法修改这些前端详细信息。 |
| `woocommerce_checkout_show_terms` | 不支持 ❌ | 此项无法通过此过滤器控制。 可以在编辑器中删除此块。 |
| `woocommerce_get_privacy_policy_text` | 不支持 ❌ | 不支持使用此过滤器修改隐私政策文本。 可以在编辑器中进行修改。 |
| `woocommerce_order_button_html` | 不支持 ❌ | 不支持使用此钩子修改“购物车”/“结账”块中的订单按钮 HTML - 请在编辑器中进行修改。 |
| `woocommerce_update_order_review_fragments` | 不支持 ❌ | “购物车”/“结账”块不使用片段。 |

**重要说明:**

*   **Page:** 网页
*   **Hook:** 钩子
*   **API:** API
*   **Privacy Policy:** 隐私政策
*   **Form fields:** 表单字段
*   **Extensions:** 扩展
*   **Registered:** 注册
*   **Checkbox:** 复选框
*   **Quantity:** 数量
*   **Register:** 注册
*   **Subtotal:** 小计
*   **Message:** 信息
*   **Requests:** 请求
*   **Shipping:** 配送
*   **Checkout:** 结账
*   **Address:** 地址
*   **Details:** 详情
*   **Privacy:** 隐私
*   **Summary:** 摘要
*   **Display:** 显示

### 提交订单 _操作_

本部分正在进行中。

### 提交订单 _筛选器_

本部分正在进行中。

### 订单摘要 _操作_

本部分正在进行中。

### 订单摘要 _筛选器_

本部分正在进行中。

## 常见的扩展方式

### 购物车和结账模块

#### 完全支持，无需修改

- 修改购物车中的费用和其他价格 (`woocommerce_cart_calculate_fees`)
- 在 WC 生命周期事件期间更新客户信息，例如在 `woocommerce_init` 中，更新客户的地址会反映在购物车/结账模块中。
- 添加付款方式
- 使用 `woocommerce_product_get_name` 更改产品名称

#### 部分支持或通过替代方法支持

- 修改布局，例如在特定部分（如配送、付款以及账单/配送地址）之前/之后插入内容。例如：在各种位置输出内容，例如在打印购物车内容之前 (`woocommerce_cart_contents`) 和在显示运费之前 (`woocommerce_before_shipping_rate`)：
    - 这通过我们的 Slot/Fill 功能以及通过将内部块注册为要显示的块的子块来实现。
- 添加付款方式
    - 仅仅添加付款方式是不够的，开发者还需要注册一个 React 组件，以便在付款模块中显示。
- 添加本地自提的配送方式
    - 应该可以正常工作，但需要该方式支持本地自提功能。
- 修改购物车中商品的名称
    - 需要开发者使用 JavaScript 筛选器，而不是 PHP 筛选器。

#### 完全不支持

- 修改单个购物车项目以添加或更改内容/更改 HTML（超出我们结账筛选器提供的范围）。

### 结账模块

#### 完全支持，无需修改

- 预填充表单中的值（一些商家通过覆盖其值来实现，使用 `woocommerce_checkout_get_value`）
    - 只要购物车/客户对象中设置的值，我们都会尊重这些值。 `woocommerce_checkout_get_value` 不在结账模块中支持，但这是该钩子的唯一用例。

#### 部分支持或通过替代方法实现

- 添加新的结账字段（通常通过 `woocommerce_checkout_fields` 钩子实现）
    - 通过附加结账字段 API 支持，但目前并非所有字段类型都受支持。
- 使用钩子（如 `woocommerce_checkout_process`）进行自定义字段验证
    - 通过钩入支付处理事件支持，验证发生在点击“提交订单”时，这仅适用于付款方式。其他扩展可以在点击按钮之前将验证错误添加到数据存储中，从而阻止结账，但这并不是一个好的解决方案，尤其是在验证检查成本较高的情况下。
- 在订单提交之前/期间/之后更新订单/客户（通过钩子实现）
    - 我们有一些在结账过程中触发的钩子：
        - `woocommerce_store_api_checkout_order_processed` - 订单已提交时触发。
        - `woocommerce_store_api_checkout_update_customer_from_request` - 当客户数据从结账请求中更新时触发。
        - `woocommerce_store_api_checkout_update_order_meta` - 当订单元数据从请求中更新时触发。
    - 任何其他在短代码过程中触发的 WC 钩子（例如 `woocommerce_checkout_order_processed`）不会在块中的 Store API 请求中触发。
- 使用 `woocommerce_order_button_text` 自定义“提交订单”按钮文本
    - 不支持通过钩子实现，但可以在编辑器中实现。目前没有编程方式可以实现此功能。

#### 完全不支持

- 修改现有的核心字段（通常通过 `woocommerce_checkout_fields` 钩子实现）
- 移除账单/配送地址（使用上述方法）
- 在订单最终确定之前执行操作 (`woocommerce_checkout_create_order`)

### 购物车块

#### 完全支持，无需任何修改

- 无，这些内容已经在“两个块”部分中涵盖。

#### 部分支持或通过替代方法实现

- 限制购物车中商品的数量选择，例如设置最小值、最大值或步长值。 以前，这通常通过过滤器（如 `woocommerce_quantity_input_step`）来实现。
    - 可以通过修改购物车项的 `quantity_limits` 属性，在 `woocommerce_store_api_product_quantity_{`$value_type`}` 过滤器中实现。

#### 完全不支持

- 通过修改模板文件来修改布局（除非使用块主题和自定义模板）