【发布时间】:2018-11-24 12:18:59
【问题描述】:
我使用以下代码向 Woocommerce 添加了一个名为“供应商”的新分类:
// hook into the init action and call taxonomy when it fires
add_action( 'init', 'create_vendor_taxonomy', 0 );
// create and register vendor taxonomy (hierarchical)
function create_vendor_taxonomy() {
$labels = array(
'name' => _x( 'Vendors', 'taxonomy general name', 'textdomain' ),
'singular_name' => _x( 'Vendor', 'taxonomy singular name', 'textdomain' ),
'search_items' => __( 'Search Vendors', 'textdomain' ),
'all_items' => __( 'All Vendors', 'textdomain' ),
'parent_item' => __( 'Parent Vendor', 'textdomain' ),
'parent_item_colon' => __( 'Parent Vendor:', 'textdomain' ),
'edit_item' => __( 'Edit Vendor', 'textdomain' ),
'update_item' => __( 'Update Vendor', 'textdomain' ),
'add_new_item' => __( 'Add New Vendor', 'textdomain' ),
'new_item_name' => __( 'New Vendor Name', 'textdomain' ),
'menu_name' => __( 'Vendors', 'textdomain' ),
);
$args = array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'vendor' ),
);
register_taxonomy( 'vendor', array( 'product' ), $args );
}
我想在单个产品页面上显示的类别和标签标签之间插入这个新分类。
我有一个子主题,并且了解我必须在子主题中创建一个 woocommerce 文件夹,然后将我必须编辑的 woo 模板文件的副本添加到该文件夹中。
谁能帮帮我?
- 我必须编辑哪些 woo 模板文件?
- 我需要向这些文件中添加什么代码才能将我的新分类法插入到产品页面中?
提前感谢您的任何帮助。
更新: 经过进一步研究,我似乎不需要编辑 Woo 模板文件。
在单个产品页面的类别和标签元下方有一个可用的挂钩。这样就可以了。
所以我可以使用以下内容插入供应商分类详细信息:
add_action( 'woocommerce_product_meta_end', 'insert_vendor_custom_action', 5 );
function insert_vendor_custom_action() {
global $product;
if [WHAT DO I NEED HERE?]
echo [WHAT DO I NEED HERE?];
}
感谢任何可以帮助我的人。
【问题讨论】:
标签: php wordpress woocommerce product custom-taxonomy