Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Woocommerce add upsells in database

I'm trying to add some upsells and crosssell products in woocommerce. The last thing i want to do is to add everything manually, so created query with random selected products and came up with this:

INSERT INTO wp_postmeta VALUES(DEFAULT, product_id, '_crosssell_ids', 'a:3:{i:0;s:3:"crosssell_product_id";i:1;s:3:"crosssell_product_id";i:2;s:3:"crosssell_product_id";}');

But it is not being shown under the product. Is there any flag that indicates whether this specific product has or not the upsell/crosssell associated? Is there any other way to add crosssale/upsell products?

Thanks

like image 367
Inthakhub Hossain Rayhan Avatar asked Oct 25 '25 15:10

Inthakhub Hossain Rayhan


1 Answers

I'm not sure how to do this with a query but here is php code to set the cross sells. My importer adds them this way.

wp_set_object_terms($product_id, [13, 14], '_crosssell_ids');
update_post_meta($product_id, '_crosssell_ids', [13, 14]);

[13, 14] is an array of product ids that are the cross sells.

To get the product id for a given product from our SKU, you can use:

wc_get_product_id_by_sku

like image 148
Brett Drake Avatar answered Oct 28 '25 06:10

Brett Drake