PHP code example of x-wp / wc-data-attribute-tax

1. Go to this page and download the library: Download x-wp/wc-data-attribute-tax library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

x-wp / wc-data-attribute-tax example snippets




// 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' );



$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



$attribute = xwc_get_attribute_tax( 'color' );
$wc_attr   = $attribute->get_wc_attribute( position: 0 );



// 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' );