HUSKY - Product Filter for WooCommerce

woof_template_part

允许在短代码 [ 中动态更改模板woof_products]

 

从 v.1.1.8/2.1.8 开始

 

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 在过滤过程中应用 — 更改会立即生效。
  • 始终从回调函数返回预期的值类型。