I get this error after deleted a few of unused category's product on my woo theme:
Catchable fatal error: Object of class WP_Error could not be converted to string in D:-mytheme\wordpress\wp-content\plugins\myplugin\mymodule.php on line 47
The line 47 is like this:
<?php echo '<a href="'.get_term_link($term).'">'.$term->name.'</a>'; ?>
The $term define on:
<?php
class myShortCode {
protected function content($atts, $content = null){
$atts = vc_map_get_attributes( $this->getShortcode(), $atts );
global $woocommerce, $product;
extract( shortcode_atts( array(
'title' => ''
), $atts ) );
$term = get_term_by('name', $type_product, 'brands');
$category = isset($term->term_id) ? $term->term_id : '';
$css_class = "";
if ( $css_animation != '' ) {
wp_enqueue_script( 'waypoints' );
$css_class = ' wpb_animate_when_almost_visible wpb_'.$css_animation;
}
;
ob_start();
?>
The error disappear only id the category exist and selected.
I have no idea how to fix this. Can anyone throw me a bone?
Thank you.
$term->name
check if it is not wp error object.