'Is there a way to get_tag by name only in WordPress?

I am trying to get an array of tag names for products in a specific category. The issue I am running into is when using get_tags() it is returning a link to the tag.

I would like to only return the name of the tag without the link.

Example:

$args = array(
     'category'      => 'compressors', 
     'limit'         => -1,
);
        
// Retrieving products
$comp_product_array = wc_get_products( $args );

$tags_array = array();

// Loop thru product array
foreach ( $comp_product_array as $products ) {
     $product_id = $products->get_id();
     $product_tags = $products->get_tags();
     $tags_array[] = $product_tags;
     $product_price = " +$" . $products->get_regular_price();
     $options[$product_id] = $products->get_name() . $product_price;
}
            
    var_dump($tags_array);

Output:

array (size=27)
 0 => boolean false
 1 => boolean false
 2 => boolean false
 3 => boolean false
 4 => string '<a href="http://test-site.local/product-tag/camaro/" rel="tag">Camaro</a>' (length=82)
 5 => boolean false
 6 => boolean false
 7 => string '<a href="http://test-site.local/product-tag/mustang-a-c-systems/" rel="tag">Mustang A/C Systems</a>' (length=108)
 8 => boolean false
 9 => boolean false
 10 => boolean false
 11 => boolean false
 12 => boolean false
 13 => boolean false
 14 => boolean false
 15 => boolean false
 16 => boolean false
 17 => boolean false
 18 => boolean false
 19 => boolean false
 20 => boolean false
 21 => boolean false
 22 => boolean false
 23 => boolean false
 24 => boolean false
 25 => boolean false
 26 => boolean false

The result I am looking for is 4 => string 'Camaro'.

Another option I have tried is:

$product_tags = $products->get_tags();
$tag_names = $product_tags->name;
$tags_array[] = $tag_names;

var_dump($tags_array);

The output for this is:

array (size=27)
  0 => null
  1 => null
  2 => null
  3 => null
  4 => null
  5 => null
  6 => null
  7 => null
  8 => null
  9 => null
  10 => null
  11 => null
  12 => null
  13 => null
  14 => null
  15 => null
  16 => null
  17 => null
  18 => null
  19 => null
  20 => null
  21 => null
  22 => null
  23 => null
  24 => null
  25 => null
  26 => null

Any help with this would be greatly appreciated.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source