I want to get value from woocommerce product attribute description input.
I tried $discription = $attributes->description; and also $product_attribute['description'], but it doesn't work.
If you have the product object, you can get the description like so
$productObject->get_short_description();
Otherwise initialize the product with the ID first and then get the description
$productObject = wc_get_product( $productId );
$productObject->get_short_description();
Related
I am looking for a solution which can help me get parent product category from child product. I am showing product category and product name of each product in yith woocommerce wishlist. Simple Products are working fine but when i am adding a Variable Product then product category in not showing.
echo $product->get_categories();
This code is responcible for showing category of Simple Products what I can do for Variable Product.
Now How I can get product category of parent product of a variable product in wishlist.
Try adding this in front of your echo statement:
$product = $product->get_parent_id() ? wc_get_product( $product->get_parent_id() ) : $product;
It should set the $product variable to the parent product object if you are dealing with the variable product object.
(untested)
I saw this, WooCommerce - Get the product description by product_id
But I was hoping there was a shorter way to get the product by ID and get the description? Any idea?
I'm using WooCommerce 3.0 and above.
In your question, we don't know what do you mean by "GRAB"… It can be how to SET (or how to GET) the product description.
There is multiple ways to SET the product description.
1) From the product ID using Wordpress wp_update_post();
wp_update_post( array('ID' => $product_id, 'post_content' => 'This is the <strong>product description</strong> content.') );
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
There is multiple ways to GET the product description (as explained in this thread).
1) From the product ID, using Wordpress get_post() function:
$product_description = get_post( $product_id )->post_content;
2) From the WC_Product Object using get_description() method
// Get the WC_Product Object instance (optional if needed)
$product = wc_get_product( $product_id );
// Get the product description
$description = $product->get_description();
I am trying to show the price of a product in a post by code using HTML.
I am trying to utilize $product->get_price(). however, I need to be able to call the product by identifying it, using its code or something like it.
So Basically, all I want to do is to show the price of a particular product in the post by using a product ID as reference for example.
Any idea?
If you have the product's ID you can use that to create a product object:
$_product = wc_get_product( $product_id );
Then from the object you can run any of WooCommerce's product methods.
$_product->get_regular_price();
$_product->get_sale_price();
$_product->get_price();
Hope this one helps.
you use wc_get_product function :
$_product = wc_get_product( $product_id );
$_product->get_regular_price();
$_product->get_sale_price();
$_product->get_price();
I built a custom payment gateway extension for woocommerce and I'm posting all the data (item name, cost, quantity etc) in JSON format back to the payment provider.
However, I can't seem to get the item description to go through.
Any ideas?
You can have that in cart object items, when getting an instance of the WP_post object, this way:
foreach(WC()->cart->get_cart() as $cart_item){
// Get an instance of Product WP_Post object
$post_obj = get_post( $cart_item['product_id'] );
// HERE the product description
$product_desciption = $post_obj->post_content;
// The product short description
$product_short_desciption = $post_obj->post_excerpt;
}
WooCommerce: Adding the Product Short Description to Archive Pages or Show Products Short Description on Shop Page
function vitahc_excerpt_in_product_archives() {
the_excerpt();
}
add_action('woocommerce_after_shop_loop_item_title','vitahc_excerpt_in_product_archives', 10);
In category view, I want to show an overlay containing product's data, such as brand, manufacturer, tax rate and so on. I can display an overlay (using JavaScript's onmouseover event) and retrieve an id of the product from the URL, but I don't know how to retrieve all data of particular product. What's the simplest way to retrieve all data of particular product based on its id?
Use the below code to get product Information based on Product Id
$_product = Mage::getModel('catalog/product')->load($product_id); // Enter your Product Id in $product_id
echo $_product->getName(); // get Product's name
echo $_product->getShortDescription(); //get product's short description
echo $_product->getDescription(); //get Product's Long Description
echo $_product->getPrice(); //get Product's Regular Price
echo $_product->getSpecialPrice(); //get Product's Special price
echo $_product->getProductUrl(); //get Product's Url
echo $_product->getImageUrl(); //get Product's image Url
If you need attributes like brand and manufacturer for that product you can get in same way.