PHP Add products to cart with WooCommerce Addons

The WooCommerce Cart add_to_cart function takes a parameter for cart_item_data. To make this work, you simply need to pass the addon data to add_to_cart. Something like this: $addons = array( array( “name” => “Size”, “value” => “2.5×7”, “price” => 0, “field_name” => “5186-0”, “field_type” => “multiple_choice”, “id” => “1683555538”, “price_type” => “flat_fee” ), array( “name” … Read more

How can I update a value of a field depending on outside source?

you can read your file using standard PHP: $value = json_decode( file_get_contents( ‘path/to/your/file.json’ ) ); Then you can use WordPress function to update post meta: update_post_meta( $post_id, $meta_name, $value, $prev_value ); $post_id = ID of the post you want to update $meta_name = name of the meta field you want to update $value = new … Read more

How to use phpspreadsheet reader with $wpdb

I’m assuming you mean this PhpSpreadsheet; if not, please edit your question to clarify. To incorporate any third-party PHP library into your WordPress site, you’ll either need to write a plugin or find one that already does what you need. The PhpSpreadsheet docs explain how you’d incorporate their library into any PHP application, which includes … Read more

Running a long script in PHP

You can add some settings to your script to reduce count of imported products in one run. The simplest way – add fields like “Import from” and “Imported count”. You can run your script several times playing with “Import from” parameter and import 200 products (for example) per one time.