Finally I got it working with next code:
$product = wc_get_product($productId);
$attrName="my_attribute";
$attrValue="some value"
$attr = new WC_Product_Attribute();
$attr->set_name( $attrName );
$attr->set_options( [$attrValue] );
$attr->set_visible(1);
$attr->set_variation(1);
$attr->set_position(0);
$attr->set_id( 0 );
$attrs[$attrName] = $attr;
$product->set_attributes($attrs);
$product->save();
Related Posts:
- WooCommerce create new product and add to cart on form submit
- How to set value/term of a Woocommerce attribute text field in admin panel?
- How to add product images using script?
- Can’t create term for product attribute
- Manually add order item with fixed product_id in WooCommerce
- custom payment gateway in woocommerce failed to connect to remote api server
- creating a custom shop page display on archive woocommerce
- Redirect to another page using contact form 7? [closed]
- I am trying to make a field show and save from quickedit screen
- .php file for woocommerce edit category? [closed]
- I want to filter my products with attributes [closed]
- Automatic recurring payment using YITH subscription and Dokan Stripe
- woocommerce remove coupon link does not work
- Hide fields in woocommerce settings
- Adding discount functionality to the cart
- How to assign a specific service to a specific provider based on location
- Woocommerce list variations that are added already to cart in Single Product
- Automatically check “Enable stock management at product level” to the existing products?
- Woocommerce quick checkout form [closed]
- Need help saving input fields for Security Deposit plugin in WC Vendors page
- Create Custom Coupon Type
- Product customizing quiz – quiz adding products to the cart
- is_plugin_active function doesn’t exist
- Proper Way to Modify Plugin
- Hide prices and checkout functionality in woocommerce
- Looking for a Table of Contents (TOC) plugin for WordPress
- WordPress Plugin Development In MVC Architecture, How?
- Where should I use get_option in a plugin
- GPL and plugins
- Disable Specific Widgets on Selected Pages of a WordPress Website?
- Create page when plugin is activated
- Function to Set Product type in Woocommerce [closed]
- How to show custom message once on plugin activation?
- wp_schedule_event / cron_schedules – custom recurrence time not working in Plugin
- How to load a new template page according to a particular URL?
- WordPress network: set themes and plugins for new blog
- Can a plugin add to header/footer/body content?
- Woocommerce Shipping module available only for type of products [closed]
- WooCommerce – Adding Custom Order Without No Product [closed]
- Organising the plugins folder in wordpress
- force customers to add only single item to card per purchase EDD [closed]
- Preventing BFA in WordPress without using a plugin
- Output HTML only on individual post view
- ‘Customize’ button in admin bar for CSS
- WooCommerce shop page orderby [closed]
- How to show Recent Page instead of Post?
- Reduce Drop down Menu Width in WordPress
- How would I go about creating a user ranked post popularity page?
- How to modify WCMP Rest API response?
- Woocommerce dependent plugin
- CampaignMonitor for WooCommerce – Move subscribe button [closed]
- Pre booking doesn’t work with custom bootstrap modul in woocommerce [closed]
- Why can’t I access my Intranet LDAPS with NADI?
- Setup page on first login on multisite
- Integrating WP E-commerce plugin into custom theme
- Custom post types – remove default post supports through empty array?
- How to get a list of bundled products using wp_query in woocommerce
- When I try to de-activate any plugin it gives error “Warning: call_user_func_array() [function.call-user-func-array]”
- How to get the particular product quantity in orders in Woocommerce [closed]
- Is it possible to instantiate a new WC_Cart?
- Sell access to form [closed]
- Action on WordPress Install
- Delete data from custom table when deleting a post
- What is the best way to make a custom page from a plugin?
- apply_filters(woocommerce_get_item_data, …) Causing errors when adding to cart
- Change Dashboard URL from wp-admin to wp-admin/index.php
- How to customize maintenance mode notification in wordpress?
- How To Use do_shortcode with WooCommerce One Page Checkout
- implement custom roles in custom plugin
- Custom Plugin: How to Include Install Buttons of other 3rd Party Plugins?
- show wc_add notices on particular page in woo commerce custom plugin development
- One WooCommerce Store to multi distributor sites
- Custom form data not displaying in cart page?
- best way to handle subscriptions with a licence?
- Cron job shedules replace?
- woocommerce with external ftp site
- WordPress eMails not working
- Add WooCommerce vendor slug to auto-generated SKU
- Custom plugin issue – Notice: Trying to get property of non-object in
- fetch price from different table woocommerce
- Cannot save a custom meta field in quick edit
- Customize plugin templates
- how to make settings page for woocommerce plugin?
- redirect to a custom page
- How to use custom footer template in a site-plugin?
- Problem with conditional woocommerce custom checkout field
- Customize a widget position
- Why the output of an image gallery plugin is not displayed into a page of my custom theme?
- How woo-commerce store Product Data value in DB?
- Which WordPress version to use for improved plugin compatibility? [closed]
- Pronamic Info Window
- From a legal perspective, is it okay to customize a plugin’s code?
- Trying to disable all notifications except for one on woocommerce checkout page with css [closed]
- Child Plugin Admin Panel
- Does anyone have the Custom Post Permalinks plugin from John P. Bloch? [closed]
- Translate text for empty product
- Resources for building a custom event page template
- WooCommerce REST API aborts connection [closed]
- How to make a Template page to show the information of different things Shop and Product page?
- How to create different woocommerce single_product.php pages for each product? [closed]