How can i create a WooCommerce product programatically or using sql query?

This will give you a base to start: function generate_simple_product() { $name=”My Product Name”; $will_manage_stock = true; $is_virtual = false; $price = 1000.00; $is_on_sale = true; $sale_price = 999.00; $product = new \WC_Product(); $image_id = 0; // Attachment ID $gallery = self::maybe_get_gallery_image_ids(); $product->set_props( array( ‘name’ => $name, ‘featured’ => false, ‘catalog_visibility’ => ‘visible’, ‘description’ => … Read more

Woocommerce product download URL

<?php $downloads = $product->get_files(); foreach( $downloads as $key => $download ) { echo ‘<p class=”download-link”><a href=”‘ . esc_url( $download[‘file’] ) . ‘”>’ . $download[‘name’] . ‘</a></p>’; } ?> Check this.. Worked for me.

How to get customfield value by woocommerce product ID

If you look for all products with same ‘product_cip’ value try this: $a=array( ‘post_type’ => ‘product’, ‘post_status’ => ‘publish’, ‘posts_per_page’ => – 1, ‘meta_query’ => array( array( ‘key’ => ‘product_cip’, ‘value’ => ‘some value’, ‘compare’=> ‘=’ ) ), ‘fields’ => ‘ids’ ); $b=get_posts($a); echo count($b); if you have get all products data $products_array=array(); foreach($b as … Read more

Manually add order item with fixed product_id in WooCommerce

I know is a little bit late but maybe my anwser is helpfuly for someone else. I used WordPress in version 4.9.7 and WooCommerce in version 3.4.3 To extend the buttons you can use the woocommerce action “woocommerce_order_item_add_action_buttons“. You find the declaration of that action in the file “woocommerce/includes/admin/meta-boxes/views/html-order-items.php” The following code use this action … Read more

Separate Categories from WC Product loop when display type is set to both on the category

I have found the solution I was looking for. Using the following code will stop displaying categories in the product loop. remove_filter( ‘woocommerce_product_loop_start’, ‘woocommerce_maybe_show_product_subcategories’ ); Then use the following function in a separate section of the page will render the categories in a separate section. woocommerce_maybe_show_product_subcategories()

global $post; in WooCommerce

You should avoid using global variables where possible. For metaboxes you should use the $post variable that is passed to the callback function instead: add_meta_box( ‘supplier_package_box’, __( ‘Supplier’, ‘supplier’ ), ‘populate_meta_box’ ); function populate_meta_box( $post ){ print_r($post); }