Looking for help?
< All Topics
Print

Add variable attribute info to variation products


add_filter('op_product_data',function($product_data){
    if(!empty($product_data))
    {
        $_product = wc_get_product($product_data['id']);

        if($_product->get_type() == 'variation')
        {
           $product_data['display_search'] = 'no';
           $variation_attributes = $_product->get_attributes();
           $attribute_str = implode(',',$variation_attributes);
           $parent_id = $_product->get_parent_id();
           $parent_product = wc_get_product($parent_id);
           $name = $_product->get_name();
           if($parent_product)
           {
               $name = $parent_product->get_name();
           }
           if($name)
           {
               $product_data['name'] = $name.' - '.$attribute_str;
           }
        }
    }
    
    return $product_data;
},1001,2);
Table of Contents