x-wp/wc-data-attribute-tax
最新稳定版本:v1.0.1
Composer 安装命令:
composer require x-wp/wc-data-attribute-tax
包简介
WooCommerce attribute taxonomy data objects
README 文档
README
WC Data Attribute Tax
WooCommerce attribute taxonomy data objects
This package provides XWC_Attribute_Tax data objects for working with WooCommerce product attribute taxonomies. Built on the x-wp/wc-data-type framework, it wraps WooCommerce's wc_*_attribute() functions in a model-driven CRUD workflow with typed properties, a dedicated factory, and convenience helpers.
Installation
composer require x-wp/wc-data-attribute-tax
Tip
We recommend using automattic/jetpack-autoloader with this package to reduce autoloading conflicts in WordPress environments.
Usage
Loading an attribute
<?php // By ID $attribute = xwc_get_attribute_tax( 5 ); // By name/slug $attribute = xwc_get_attribute_tax( 'color' ); // By label (creates if it doesn't exist) $attribute = XWC_Attribute_Tax::from_label( 'Color' );
Working with attribute properties
<?php $attribute = xwc_get_attribute_tax( 'color' ); $attribute->get_label(); // 'Color' $attribute->get_name(); // 'color' $attribute->get_type(); // 'select' $attribute->get_orderby(); // 'menu_order' $attribute->get_public(); // true $attribute->get_taxonomy_name(); // 'pa_color' $attribute->get_terms(); // array of WP_Term objects
Converting to WC_Product_Attribute
<?php $attribute = xwc_get_attribute_tax( 'color' ); $wc_attr = $attribute->get_wc_attribute( position: 0 );
Utility functions
<?php // Data store access $data_store = xwc_att_ds(); // Get attribute by ID (with default) $attribute = xwc_get_attribute_tax( $id, false ); // Get a fresh instance by ID $attribute = xwc_get_attribute_tax_object( $id ); // Find attribute ID by label $id = xwc_get_attribute_tax_id_by_label( 'Color' );
Testing
The package ships with a PHPUnit suite that boots a WordPress + WooCommerce test environment.
Local prerequisites:
- Docker with
docker compose - PHP
- WP-CLI (
wp) - MySQL client tools (
mysqlandmysqladmin) curlunzip
Run the suite with:
composer test
To prepare the local WordPress test environment first:
composer test:install
composer test
composer test:install starts the MySQL service, downloads WordPress, installs WooCommerce, and prepares the WordPress test suite under .cache/wp-tests.
To fully reset the local test environment:
composer test:clean
That command stops the test containers and removes the cached WordPress test files.
Documentation
Core classes:
XWC_Attribute_Tax— attribute taxonomy entityXWC_Attribute_Tax_Factory— string-aware factory for resolving attributes by name or labelXWC_Attribute_Tax_Data_Store— data persistence layer using WooCommerce attribute functions
For framework-level documentation, see x-wp/wc-data-type.
统计信息
- 总下载量: 4
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-04-06