Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wordpress Woocommerce - use update_post_meta to add product attributes

Tags:

People also ask

How do I add a product attribute in WooCommerce?

Go to: Products > Add Product (or edit an existing one). Select the Attributes tab in the Product Data. There you can choose any of the attributes that you've created in the dropdown menu. Select Add.

How does WooCommerce show attributes on shop page?

Log in to your WordPress account and go to the dashboard. There, navigate to Products and select the products you want to show the product attributes. If you want to create a new product, click on Add Product. If you just want to edit the existing one, select the Edit button below the item.

Where are WooCommerce product attributes stored?

Product attributes are stored in two locations - in wp_terms, wp_term_taxonomy and wp_term_relationships (that's the first place - each attribute is preceded by pa_ for its taxonomy name - e.g. if you have a color attribute, it's under pa_color) then also as a PHP serialized array in wp_postmeta under '_ ...


The products in my clients website require certain attributes which I have added via Products -> Attributes in the Wordpress administration. In this import script I'm coding I need to use the function update_post_meta($post_id, $meta_key, $meta_value) to import the proper attributes and values.

Currently I have the function like so:

update_post_meta( $post_id, '_product_attributes', array());

However I'm not sure how to properly pass along the attributes and their values?