Search
 
SCRIPT & CODE EXAMPLE
 

PHP

How to programmatically grab the product description in WooCommerce?

2) From the WC_Product Object using set_description() method
// Get the WC_Product Object instance (optional if needed)
$product = wc_get_product( $product_id );

// Set the description
$product->set_description('This is the <strong>product description</strong> content.');

$product->save(); // Save product data
Comment

woocommerce import product programmatically

function myCustomProduct($product_array)
{
    if (!empty($product_array)):
        foreach ($product_array as $product):
            $product_id = wc_get_product_id_by_sku($product['sku']);
            //no product exist with the given SKU so create one
            if (!$product_id):
                $post = [
                    'post_author' => '',
                    'post_content' => $product['content'],
                    'post_status' => "publish",
                    'post_title' => wp_strip_all_tags($product['title']),
                    'post_name' => $product['title'],
                    'post_parent' => '',
                    'post_type' => "product",
                ];
                //Create Post
                $product_id = wp_insert_post($post, $wp_error);

                //set Product Category
                wp_set_object_terms($product_id, $product['product_cat'], 'product_cat');

                //set product type
                wp_set_object_terms($product_id, 'simple', 'product_type');

                update_post_meta($product_id, '_sku', $product['sku']);
                update_post_meta($product_id, 'total_sales', '0');

            //product found
            else:
                $post = [
                    'ID' => $product_id,
                    'post_title' => $product['title'],
                    'post_content' => $product['content'],
                ];
                $post_id = wp_update_post($post, true);
//              if (is_wp_error($post_id))
//              {
//                  $errors = $post_id->get_error_messages();
//                  foreach ($errors as $error)
//                  {
//                      echo $error;
//                  }
//              }
            endif;

            update_post_meta($product_id, '_visibility', 'visible');
            update_post_meta($product_id, '_stock_status', 'instock');
            update_post_meta($product_id, '_product_attributes', array());
            update_post_meta($product_id, '_manage_stock', "yes");
            update_post_meta($product_id, '_backorders', "no");
            update_post_meta($product_id, '_stock', $product['qty']);
            update_post_meta($product_id, '_price', $product['price']);
            //update_post_meta($product_id, '_downloadable', 'yes');
            //update_post_meta($product_id, '_virtual', 'yes');
            //update_post_meta($product_id, '_regular_price', "1");
            //update_post_meta($product_id, '_sale_price', "1");
            //update_post_meta($product_id, '_purchase_note', "");
            //update_post_meta($product_id, '_featured', "no");
            //update_post_meta($product_id, '_weight', "");
            //update_post_meta($product_id, '_length', "");
            //update_post_meta($product_id, '_width', "");
            //update_post_meta($product_id, '_height', "");
            //update_post_meta($product_id, '_sale_price_dates_from', "");
            //update_post_meta($product_id, '_sale_price_dates_to', "");
            //update_post_meta($product_id, '_price', "1");
            //update_post_meta($product_id, '_sold_individually', "");
        endforeach;
    endif;
}
Comment

How to programmatically grab the product description in WooCommerce?

wp_update_post( array('ID' => $product_id, 'post_content' => 'This is the <strong>product description</strong> content.') );
Comment

PREVIOUS NEXT
Code Example
Php :: symmetric decryption in php 
Php :: php print products with attribute 
Php :: list database table rows plugin wordpress 
Php :: laravel tips 
Php :: wp_remote_post decode data 
Php :: Program to Multiply Two Numbers in php 
Php :: How to Create a Transient PHP wordpress 
Php :: laravel permit only some inputs 
Php :: how to select and deselect all items without use name in laravel 
Php :: print select sql result in php 
Php :: checks whether the session is set or not, if not it will redirect the user to login page. 
Php :: laravel multiple status for a attribute in laravel migration 
Php :: Jolt transform specification input 
Php :: php sort multidimensional array by child value 
Php :: Codeingiter Pagination 
Php :: php get epoch timestamp of date 
Php :: laravel class is not recognized in tinker 
Php :: php random number routing 
Php :: Unsupported type passed 
Php :: wordpress single_cat_title slug 
Php :: AAPL_041621C125@3.25SL2.00 
Php :: solaris 11 php mysql 
Php :: searching for new lines 
Php :: Laravel route returning error 404 when attempt is made to pass value to controller function 
Php :: laravel collection flip 
Php :: php only includable file 
Php :: split php 
Php :: modal form with php 
Php :: laravel 6 migration add column to existing table 
Php :: remove exact characters from string using php 
ADD CONTENT
Topic
Content
Source link
Name
9+4 =