Home > Back-end >  Add brand type to WooCommerce
Add brand type to WooCommerce

Time:09-03

I am trying to add the Brand Name to rich data in Woocommerce. Before i used the code below, but Google has updated their guidance on how to do this. It used to be "Brand":"Brandname"; but they changed it to: “brand”: {“@type”: “Brand”, “name”: “Brandname”}.

Could somebody help me adjust the code below to include the new markup structure?

function custom_woocommerce_structured_data_product ($data) {
    global $product;
    
    $data['Brand'] = $product->get_attribute('Fabrikant') ?? null;
    $data['mpn'] = $product->get_sku() ?? null;
    
    return $data;
}
add_filter( 'woocommerce_structured_data_product', 'custom_woocommerce_structured_data_product' );

CodePudding user response:

Just replace your code snippet with below codes -

function custom_woocommerce_structured_data_product ($data) {
    global $product;
    $data['brand'] = array(
        '@type'         => 'Brand',
        'name'          =>  ( $product->get_attribute('Fabrikant') ) ? $product->get_attribute('Fabrikant') : null,
    );
    $data['mpn'] = ( $product->get_sku() ) ? $product->get_sku() : null;
    
    return $data;
}
add_filter( 'woocommerce_structured_data_product', 'custom_woocommerce_structured_data_product' );
  • Related