Forum Replies Created

Viewing 15 replies - 16 through 30 (of 36 total)
  • Thread Starter houssem12

    (@houssem12)

    Thread Starter houssem12

    (@houssem12)

    thanks for helping me out and how i can do that
    “css on the product block”

    Thread Starter houssem12

    (@houssem12)

    thanks a lot for helping me but i tested not work for me
    i want in the product page i want to show the product in list view without placeholder of the image

    Thread Starter houssem12

    (@houssem12)

    please help i will go step by step until i achieve my goals

    Thread Starter houssem12

    (@houssem12)

    ok thanks for reply
    i only need how to upload image from directory folder

    Thread Starter houssem12

    (@houssem12)

    how to add the image gallery and the attribute created to the product

    $objProduct = new WC_Product_Variable();
    $objProduct->set_name($Articlename);
    $objProduct->set_status("publish");  // can be publish,draft or any wordpress post status
    $objProduct->set_catalog_visibility('visible'); // add the product visibility status
    $objProduct->set_description($description);
    $objProduct->set_short_description($short_description);
    $objProduct->set_sku(""); //can be blank in case you don't have sku, but You can't add duplicate sku's
    $objProduct->set_price(""); // set product price
    $objProduct->set_regular_price(""); // set product regular price
    $objProduct->set_manage_stock(true); // true or false
    $objProduct->set_stock_quantity(10);
    $objProduct->set_stock_status('instock'); // in stock or out of stock value
    $objProduct->set_backorders('no');
    $objProduct->set_reviews_allowed(true);
    $objProduct->set_sold_individually(false);
    $objProduct->set_category_ids(array(92)); // array of category ids, You can get category id from WooCommerce Product Category 
    $product_id = $objProduct->save();
    Thread Starter houssem12

    (@houssem12)

    and to creat attribute for the product is :

    $attributes = array(
    	array("name"=>"Size","options"=>array("S","L","XL","XXL"),"position"=>1,"visible"=>1,"variation"=>1),
    	//array("name"=>"Color","options"=>array("Red","Blue","Black","White"),"position"=>2,"visible"=>1,"variation"=>1)
    );
    if($attributes){
    	$productAttributes=array();
    	foreach($attributes as $attribute){
    		$attr = wc_sanitize_taxonomy_name(stripslashes($attribute["name"])); // remove any unwanted chars and return the valid string for taxonomy name
    		$attr = 'pa_'.$attr; // woocommerce prepend pa_ to each attribute name
    		if($attribute["options"]){
    			foreach($attribute["options"] as $option){
    				wp_set_object_terms($product_id,$option,$attr,true); // save the possible option value for the attribute which will be used for variation later
    			}
    		}
    		$productAttributes[sanitize_title($attr)] = array(
    			'name' => sanitize_title($attr),
    			'value' => $attribute["options"],
    			'position' => $attribute["position"],
    			'is_visible' => $attribute["visible"],
    			'is_variation' => $attribute["variation"],
    			'is_taxonomy' => '1'
    		);
    	}
    	update_post_meta($product_id,'_product_attributes',$productAttributes); // save the meta entry for product attributes
    }
    //Below Code is Used to add Product Variants.
    
    $variations = array(
    	array("regular_price"=>"","price"=>"","sku"=>"ABC1","attributes"=>array(array("name"=>"Size","option"=>"L")),"manage_stock"=>1,"stock_quantity"=>10)
    //	array("regular_price"=>10.11,"price"=>10.11,"sku"=>"ABC2","attributes"=>array(array("name"=>"Size","option"=>"XL"),array("name"=>"Color","option"=>"Red")),"manage_stock"=>1,"stock_quantity"=>10)
    	
    );
    if($variations){
    	try{
    		foreach($variations as $variation){
    			$objVariation = new WC_Product_Variation();
    			$objVariation->set_price($variation["price"]);
    			$objVariation->set_regular_price($variation["regular_price"]);
    			$objVariation->set_parent_id($product_id);
    			if(isset($variation["sku"]) && $variation["sku"]){
    				$objVariation->set_sku($variation["sku"]);
    			}
    			$objVariation->set_manage_stock($variation["manage_stock"]);
    			$objVariation->set_stock_quantity($variation["stock_quantity"]);
    			$objVariation->set_stock_status('instock'); // in stock or out of stock value
    			$var_attributes = array();
    			foreach($variation["attributes"] as $vattribute){
    				$taxonomy = "pa_".wc_sanitize_taxonomy_name(stripslashes($vattribute["name"])); // name of variant attribute should be same as the name used for creating product attributes
    				$attr_val_slug =  wc_sanitize_taxonomy_name(stripslashes($vattribute["option"]));
    				$var_attributes[$taxonomy]=$attr_val_slug;
    			}
    			$objVariation->set_attributes($var_attributes);
    			$objVariation->save();
    		}
    	}
    	catch(Exception $e){
    		// handle exception here
    	}
    Thread Starter houssem12

    (@houssem12)

    thanks for answering me
    i already have the code to creat a variable product with the attribute (creation/set) to the product so that is amazing
    also i have the image upload code and i still not undersatand how i get it to work

    for making you in touch with me and make things simple the text file i want generate it looks like this:
    ProductTitle,description,categoryID,short_description,Attribute,imageUrl1,imageUrl2,imageUrl3
    and the code to creat the imageUpload and set it to the product

    //Below code is used if you want to upload images of product
    function uploadMedia($image_url){
    	require_once('wp-admin/includes/image.php');
    	require_once('wp-admin/includes/file.php');
    	require_once('wp-admin/includes/media.php');
    	$media = media_sideload_image($image_url,0);
    	$attachments = get_posts(array(
    		'post_type' => 'attachment',
    		'post_status' => null,
    		'post_parent' => 0,
    		'orderby' => 'post_date',
    		'order' => 'DESC'
    	));
    	return $attachments[0]->ID;
    }
    // above function uploadMedia, I have written which takes an image url as an argument and upload image to wordpress and returns the media id, later we will use this id to assign the image to product.
    $productImagesIDs = array(); // define an array to store the media ids.
    $images = array("image1 url","image2 url","image3 url"); // images url array of product
    foreach($images as $image){
    	$mediaID = uploadMedia($image); // calling the uploadMedia function and passing image url to get the uploaded media id
    	if($mediaID) $productImagesIDs[] = $mediaID; // storing media ids in a array.
    }
    if($productImagesIDs){
    	$objProduct->set_image_id($productImagesIDs[0]); // set the first image as primary image of the product
    
            //in case we have more than 1 image, then add them to product gallery. 
    	if(count($productImagesIDs) > 1){
    		$objProduct->set_gallery_image_ids($productImagesIDs);
    	}
    }
    //save the product to get WooCommerce Product ID
    $product_id = $objProduct->save(); // it will save the product and return the generated product id
    Thread Starter houssem12

    (@houssem12)

    thank you for answering me but i only need to make the atribute appear like a simple text
    not drop down or anything else
    please help

    Thread Starter houssem12

    (@houssem12)

    yap i get it and undertand it
    but there is only update/modify a product how i can creat it

    Thread Starter houssem12

    (@houssem12)

    catacaustic(@catacaustic)
    i am not undertanding how it work and how it will solve my problem

    Thread Starter houssem12

    (@houssem12)

    and i am thinking if any idea that i can creat or get another dashboard where to add product in woocommece plugin
    like this will solve my problem

    Thread Starter houssem12

    (@houssem12)

    i get an error
    Network error : software caused connection abort

    Thread Starter houssem12

    (@houssem12)

    this is the connection i used

    Dim substitution2 As New MySqlConnection("host=***.mysql.db;Port=3306;database=***;username=***;password="";")
    and the error i get is the host is unknown

    • This reply was modified 5 years, 2 months ago by houssem12.
    • This reply was modified 5 years, 2 months ago by houssem12.
    • This reply was modified 5 years, 2 months ago by Yui. Reason: some possibly sensitive data removed
    Thread Starter houssem12

    (@houssem12)

    thanks for reply
    and what to do to connect
    please give me the steps that i follow
    for the database i can only enter to remotly with their dashboard also the dashboard of wordpress and i can with filezilla using ftp

Viewing 15 replies - 16 through 30 (of 36 total)