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
- How to get selected variation from URL?
- Need to add custom cart item data
- 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
- 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
- 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
- ‘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
- Woocommerce Shop page variation product button replace with add to cart button
- woocommerce with custom post type
- WooCommerce – set session with new cart item meta when updating cart item quantity [closed]
- Woocommerce singe product custom gallery output works just on the first slide
- How to include a custom field in the woocommerce email?
- WordPress – source link plugin – how to modify it?
- Remove Pagination for Product Category Pages WooCommerce
- add seperate suffix for low price and high price in woocommerce
- Get products list by url key in WordPress Woocommerce [closed]
- Override a Plugin Function
- Add key and value to an array in another file
- How to keep plugin (media-sync) running even the tab is closed?
- Elementor: How to design Dropdown Select Box Navigation page like Chegg
- Visual composer custom element error
- How to access a wordpress plugin page or add posts without doing it from the WordPress dashboard?
- Plugin which unlock free gift when you reach some amount in cart
- Optimise wordpress database using SQL after deleting registered images from Media Folder
- is there a way to display product gallery images via cdn
- Woocommerce redirection if no previous orders
- Move plugin pages from dashboard to front-end
- Creating custom “player-objects”
- save short-code in my custom plugin settings problem missed something
- Installation failed, trying to install ANY plugin
- Object of class WP_Error could not be converted to string in /formatting.php
- register_activation_hook not creating table
- wordpress plugin translation not working
- Many to many relationship for variable products
- Multi-site error wordpress after migration
- change product image url in widgets & shop page
- Update Plugin Without Overwriting Custom Settings
- Problems with installing and deleting plugins
- wp_query for more fields plugin
- Move related products after product summary? [closed]
- Turning Existing Eccommerce Site into Multi-SIte
- Contact Form 7 Default value from url [closed]
- Woocommerce – Product Description heading [closed]
- Visual Composer Data Source?
- Woocommerce disable checkout on specific day
- Hook for single product thumbnail
- Custom gutenberg block image preview not working
- WordPress Feature – Multi Level sorting
- How to show image caption in Woocommerce gallery
- How to add a static image inbetween the product tiles on main shoppage woocommerce?
- wp_options Table keeps growing
- Brands Filter Not Working For On Sale Products
- Can we install 3d product configurator into wordpress
- Change Custom WordPress Function [closed]
- WordPress Shipment
- WooCommerce booking error: call_user_func_array() expects parameter 1 to be a valid callback
- Woocommerce attatch files and custom input meta to cart items and then to order