Dynamic Product Variation in WooCommerce

Question

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!

0
WPTricks 3 years 2020-03-25T12:50:59-05:00 0 Answers 109 views 0

Leave an answer

Browse
Browse