WooCommerce添加额外自定义参数

WooCommerce 是基于 wordpress 的购物网站最有力的插件被广泛使用。WooCommerce 本身是一款免费的插件,但它提供了丰富的扩展接口,为网站的进一步开发提供了无限的可能,WooCommerce 中的标签和 WordPress 中的文章标签几乎是一个道理,有些人会认为标签和分类十分接近,没有必要使用标签。默认提供了分类和标签字段,但是,有的时候我们需要更多自定义的字段,并且显示在商品页的其他位置,这就需要在 Woocommerce 插件的商品后台增加自定义字段。
实例代码:

  1.  register_taxonomy(
  2. 'product_jibie',
  3. apply_filters( 'woocommerce_taxonomy_objects_product_cat', array( 'product' ) ),
  4. apply_filters(
  5. 'woocommerce_taxonomy_args_product_cat',
  6. array(
  7. 'hierarchical'          => true,
  8. 'update_count_callback' => '_wc_term_recount',
  9. 'label'                 => __( '级别', 'woocommerce' ),
  10. 'labels'                => array(
  11. 'name'              => __( '级别', 'woocommerce' ),
  12. 'singular_name'     => __( 'Category', 'woocommerce' ),
  13. 'menu_name'         => _x( '级别', 'Admin menu name', 'woocommerce' ),
  14. 'search_items'      => __( 'Search categories', 'woocommerce' ),
  15. 'all_items'         => __( 'All categories', 'woocommerce' ),
  16. 'parent_item'       => __( 'Parent category', 'woocommerce' ),
  17. 'parent_item_colon' => __( 'Parent category:', 'woocommerce' ),
  18. 'edit_item'         => __( 'Edit category', 'woocommerce' ),
  19. 'update_item'       => __( 'Update category', 'woocommerce' ),
  20. 'add_new_item'      => __( 'Add new category', 'woocommerce' ),
  21. 'new_item_name'     => __( 'New category name', 'woocommerce' ),
  22. 'not_found'         => __( 'No categories found', 'woocommerce' ),
  23. ),
  24. 'show_ui'               => true,
  25. 'query_var'             => true,
  26. 'capabilities'          => array(
  27. 'manage_terms' => 'manage_product_terms',
  28. 'edit_terms'   => 'edit_product_terms',
  29. 'delete_terms' => 'delete_product_terms',
  30. 'assign_terms' => 'assign_product_terms',
  31. ),
  32. 'rewrite'               => array(
  33. 'slug'         => $permalinks['category_rewrite_slug'],
  34. 'with_front'   => false,
  35. 'hierarchical' => true,
  36. ),
  37. )
  38. )
  39. );

以上代码添加到主题 functions 里,效果如下图我们添加一个 级别 字段:

© 版权声明
THE END
喜欢就支持以下吧
点赞0赞赏
分享
相关推荐
  • 暂无相关文章
评论 抢沙发