I'm setting up a new Wordpress/Woocommerce website using the Avada theme. The site is not live yet.
The store has custom product taxonomies, and as some of the taxonomy names contain a comma I've had to find a code snippet to do a workaround in PHP so that the comma is displayed without splitting the taxonomy name into two separate names (eg. Bouncy Balls, Putty and Slime). The PHP I found has replaced a double dash (--) with a comma in the front end, which appears to work as it should.
My problem is, that since I have added this code I'm getting an error at the top of the page on individual product pages:
Notice: Trying to get property 'taxonomy' of non-object in /var/sites/a/mywebsite.com/public_html/wpnew/wp-content/themes/Avada-Child-Theme/functions.php on line 32
Line 32 code:
if( $tag_arr->taxonomy == 'post_tag' && strpos( $tag_arr->name, '--' ) ) {
All of the code I inserted into functions.php is below.
I'm not sure what to try to fix this as this is all new to me and I'm learning as I go along. I have very little knowledge of PHP, besides the snippet I have found online and placed here.
if( !is_admin() ){
function comma_tag_filter( $tag_arr ){
$tag_arr_new = $tag_arr;
if( $tag_arr->taxonomy == 'post_tag' && strpos( $tag_arr->name, '--' ) ) {
$tag_arr_new->name = str_replace( '--', ', ', $tag_arr->name );
}
return $tag_arr_new;
}
add_filter( 'get_post_tag', 'comma_tag_filter' );
function comma_tags_filter( $tags_arr ) {
$tags_arr_new = array();
foreach( $tags_arr as $tag_arr ) {
$tags_arr_new[] = comma_tag_filter( $tag_arr );
}
return $tags_arr_new;
}
add_filter( 'get_terms', 'comma_tags_filter' );
add_filter( 'get_the_terms', 'comma_tags_filter' );
}
I expected this code to work without errors, but I have the error message at the top of the product pages.
Thanks for any help