Can I check if WooCommerce product is subscription? [duplicate] - wordpress

This question already has an answer here:
WooCommerce Subscriptions - Check if a product is a subscription product
(1 answer)
Closed 5 years ago.
I found some solutions but non of them seem to work.
<?php if ( get_post_type() == 'product') : ?>
Since both Subscription and Single product are type of product, is there a way to ask which product type they are?

Woo can do!
$product->is_type( $type )

Related

Get WooCommerce Order ID from Plugin [duplicate]

This question already has answers here:
Woocommerce - internal server error: Notice: id was called incorrectly
(1 answer)
How to get WooCommerce order details
(6 answers)
Get Order items and WC_Order_Item_Product in WooCommerce 3
(2 answers)
How to change order status in Woocommerce with my custom plugin
(1 answer)
Closed 1 year ago.
I'm trying to create a payment gateway and I need to get the WooCommerce order ID. Problem is the notice I'm getting and to be fair, I am new to the world of WordPress and WooCommerce.
Notice: Notice: ID was called incorrectly. Order properties should not be accessed directly.
This is my code:
public function get_order_details( $post ) {
if ( $post->post_type=="shop_order" ) :
$order = new WC_Order( $post );
if ( $order ) :
I'm later, whenever needed, referencing it like this: <?php echo $order->get_id; ?>
I'm using the latest WP and WC versions. If anyone can point me in the right direction in terms of how to get the Order ID from my plugin, I would really appreciate it.

How to change price according to variation in Woocommerce cart

I have two variations in my product. In cart page I need to choose the variations and with respective to variations I need to display the price.
How this can be done? Any track is welcome.
Kindly help me because I have searched a lot a solution for this, and I didn't anything yet that is working as I expect.
I have tried the following code in cart.php to get the variations.
<?php if( ! empty( $_product ) && $_product->get_type( 'variation' ) ){
$variation_attributes = $_product->get_variation_attributes();
$first_attribute = array_slice($variation_attributes, 0,1);
$second_attribute = array_slice($variation_attributes, 1,2); } ?>
By $first_attribute and $second_attribute, I populate the variations in a select box.
I have two attributes and four variations. So according to the variation I need to display the Price. I am not using third party PlugIn.
I believe this is already a part of WooCommerce's set up - as long as you have the variation set up specifically for X-license and X-plan you should be able to set the price to that variation.
Variation Data
Each variation may be assigned.
General:
Regular Price (required) – Set the price for this variation.
Source and full documentation: https://docs.woocommerce.com/document/variable-product/

Woocommerce Mini Cart - How to show prices excluding tax

my woocommerce mini cart shows the product price including tax by default. (the prices are shown excluding the tax all over the website) I'd like to show the prices excluding tax on mini cart, but keep showing them including tax in the main cart page. I believe it can be achieved with a hook but I wasn't able to do it. Any help would be very much appreciated.
Woocommerce provides two function wc_get_price_excluding_tax and wc_get_price_including_tax that you can use to display the product with or without tax.
What you might need to do is update your cart template file to use wc_get_price_excluding_tax to display the item price.
You can look at how these functions are implemented here: https://docs.woocommerce.com/wc-apidocs/function-wc_get_price_including_tax.html.
One thing to note that these function take a WC_Product object product as their first parameter, so you might need to get the product from the cart item first. You can do it by using wc_get_product. An example:
foreach( WC()->cart->get_cart() as $cart_item ){
$product_id = $cart_item['product_id'];
$product = wc_get_product($product_id);
// Display the price here
echo wc_get_price_excluding_tax($product);
}

How do I import flipkart products from a csv into Wordpress/WooCommerce? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 years ago.
Improve this question
I have a csv from flipkart with fields such as:
productId title description mrp price productUrl categories
Obviously these don't match up perfectly with the WooCommerce fields ( short description / long description vs description ), productId vs sku but does anyone have tips on how to go about matching these up to be compatible with WooCommerce, or can recommend any WP plugins that may do this?
Woocommerce product is also a custom post type (product) only. you can easily write your own custom importer.
Each product may have the following structure
product - parent post
-- attachment - featured image, gallery
-- product meta - options, category, tags, price, stock ...
-- variation - product variants (it also contains options, price, stock...)
the importer flow will be like
createProduct() {}
uploadImages() {}
createProductMeta() {}
createProductVariants() {}
Woocommerce already has all the necessory codes you want, refer WP_PLUGIN/woocommerce/includes/api/class-wc-api-products.php
create_product( $data ) - line number 174
save_product_images( $id, $images ) - line number 1551
save_product_meta( $id, $data ) - line number 638
save_variations( $id, $data ) - line number 1080
trust me it's easy, i have already done that ( not for flipkart but shopify to woocommerce )
For all imports you can use Wordpress wp_insert_post() function. You should create basic template for this work. Read data files with lines. And foreach it. While foreaching, define title, content or other fields.

how i get the all the details of product from product id?

In woo-commerce
i am having the product id and i need the specific details of that product lik short description,product feature image,price,and the link of product detail page.
Please help me
Have you read the WooCommerce functions documentation?
You can use wc_get_product() to return product details as a WC_Product object.
For example:
$product = get_product( $product_id );
try to look at the default product detail page. it will have some code or global variables, you can use them to get the details.
look at the functions file to get the product details.

Resources