woof-template-part
woof_template_part
允许更改用于在 [woof_products] 短代码中显示商品的模板部分的名称。
Parameters
$template (string) — 模板名称(默认为 'product')
Source File
index.php
Code Example
add_filter('woof_template_part', function($template) {
// 使用自定义模板显示商品
// 将您的模板放置在:wp-content/themes/your-theme/woof/product-custom.php
$custom_template = 'product-custom';
if (is_product_category('specials')) {
return $custom_template;
}
return $template;
});
Usage Notes
- 将此代码添加到您主题的
functions.php文件或自定义插件中。 - 此 hook 在过滤过程中应用 — 更改会立即生效。
- 始终从回调函数返回预期的值类型。