0

I installed WooCommerce and have 3 variable products, however I'd like to add the variation "language". I don't want to add as meta information for the products (in the gui), but I would like to use a hook, so I can say that every variable product has a language variation - english and german. I tried using the filter woocommerce_display_product_attributes:

add_filter('woocommerce_display_product_attributes', function($atts, $product) {
  $product_attributes = $product->get_attributes();
  $languages = new WC_Product_Attribute();
  $languages->set_id(0);
  $languages->set_name('language');
  $languages->set_options(['english','german']);
  $languages->set_position(0);
  $languages->set_visible(1);
  $languages->set_variation(1);
  return [
    $product_attributes,
    $languages
  ];
}, 10, 2);

Can someone help me out with this? I would be really grateful!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.