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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With