/**
*
* Create new taxonomy.
*
* @param $attr_name
* @param int $prefix
* @return string
*/
public function createTaxonomy($attr_name, $prefix = 1) {
$attr_name_fix = $attr_name; //зафиксил
$attr_name = substr($attr_name, 0, 27); //обрезал имя
$attr_name_real = $prefix > 1 ? $attr_name . " " . $prefix : $attr_name;
$attribute_name = wc_sanitize_taxonomy_name( stripslashes( (string) $attr_name_real ) );
// $bsk = rand(10,999);
$attribute_name = substr($attribute_name, 0, 27); //обрезал url
$args = array(
'attribute_label' => stripslashes( (string) $attr_name_fix ), //применил фикс к лейблу
'attribute_name' => $attribute_name,
'attribute_type' => 'select',
'attribute_orderby' => 'menu_order',
'attribute_public' => 1
);
if ( ! taxonomy_exists( wc_attribute_taxonomy_name( $attr_name_real ) ) ) {
if ( in_array( wc_sanitize_taxonomy_name( stripslashes( (string) $attr_name_real)), $this->reserved_terms ) ) {
$prefix++;
return $this->createTaxonomy($attr_name, $prefix);
}
else {
// Register the taxonomy now so that the import works!
$domain = wc_attribute_taxonomy_name( $attribute_name );
if (strlen($domain) < 31){
register_taxonomy( $domain,
apply_filters( 'woocommerce_taxonomy_objects_' . $domain, array('product') ),
apply_filters( 'woocommerce_taxonomy_args_' . $domain, array(
'hierarchical' => true,
'show_ui' => false,
'query_var' => true,
'rewrite' => false,
) )
);
$this->createWooCommerceAttribute($args);
$this->getLogger() and call_user_func($this->getLogger(), sprintf(__('- <b>CREATED</b>: Taxonomy attribute “%s” have been successfully created.', \PMWI_Plugin::TEXT_DOMAIN), wc_attribute_taxonomy_name( $attribute_name )));
}
else {
$this->getLogger() and call_user_func($this->getLogger(), sprintf(__('- <b>WARNING</b>: Taxonomy “%s” name is more than 28 characters. Change it, please.', \PMWI_Plugin::TEXT_DOMAIN), $attr_name));
}
}
}
else {
if ( in_array( wc_sanitize_taxonomy_name( stripslashes( (string) $attr_name_real)), $this->reserved_terms ) ) {
$prefix++;
return $this->createTaxonomy($attr_name, $prefix);
}
}
if (!wc_attribute_taxonomy_id_by_name($attr_name_real) && strlen($attribute_name) < 31) {
$this->createWooCommerceAttribute($args);
}
return $attr_name_real;
}