:::: MENU ::::
Browsing posts in: WooCommerce

WooCommerce get product tax information

Today we talk about how WooCommerce get product tax information? In our example, we will get product tax information like status, and tax class. So let’s start with our example.

If you want to load product information by it id then use the following code.

$p_id = 20;
$product_info = wc_get_product( $p_id );

Now you have product object. You can get tax infromation with the following code.

$product_info->get_tax_status(); // get product tax status
$product_info->get_tax_class(); // get product tax class
Author: Qaisar Satti
Category: WooCommerce
Last Modified: November 17, 2020


WooCommerce get product information by id

Today we talk about how in WooCommerce get product information by id? In our example, we will get product information like name, type, description, short description, SKU, modify date, create date, and status. WooCommerce uses the wc_get_product function to get the product information. So let’s start with our example.

$p_id = 20;
$product_info = wc_get_product( $p_id );
 // Get Product ID
$product_info->get_id(); // get product id
$product_info->get_type(); // get product type
$product_info->get_name(); // get product name
$product_info->get_slug(); // get product slug
$product_info->get_date_created();  // get product created date
$product_info->get_date_modified();  // get product modify date
$product_info->get_status();   // get product status
$product_info->get_catalog_visibility(); // get product visibility
$product_info->get_description(); // get product description
$product_info->get_short_description(); // get product short description
$product_info->get_sku();   // get product sku
Author: Qaisar Satti
Category: WooCommerce
Last Modified: November 17, 2020


WooCommerce get product prices

Today we talk about how WooCommerce get product price? In our example, we will get product price information like price, regular price, sale price, sale start date, and sale end date. So let’s start with our example.

If you want to load product information by it id then use the following code.

$p_id = 20;
$product_info = wc_get_product( $p_id );

Now you have product object. You can get price with the following code.

$product_info->get_price(); // get product price
$product_info->get_regular_price(); // get product regular price
$product_info->get_sale_price(); // get product sale price
$product_info->get_date_on_sale_from(); // get product sale from date
$product_info->get_date_on_sale_to(); // get product sale to date
Author: Qaisar Satti
Category: WooCommerce
Last Modified: November 17, 2020


WooCommerce get product stock information

Today we talk about how WooCommerce get product stock information? In our example, we will get product stock information like stock status, manage stock, and stock quantity. So let’s start with our example.

If you want to load product information by it id then use the following code.

$p_id = 20;
$product_info = wc_get_product( $p_id );

Now you have product object. You can get stock infromation with the following code.

$product->get_manage_stock(); // get product manage stock
$product->get_stock_quantity(); // get product stock quantity
$product->get_stock_status(); // get stock status
Author: Qaisar Satti
Category: WooCommerce
Last Modified: November 17, 2020


WooCommerce get current user information

Today we talk WooCommerce get current user information. In this tutorial, we will get the following information of the current user, user name, user email, user id, and user group. So let’s start with our example.

 $user = wp_get_current_user(); // get current user
 $id = $user->ID; // get user id
 $name = $user->user_name; // get user name
 $email = $user->email; //get user email
 $role = $user->roles[0]; // get user role
Author: Qaisar Satti
Category: WooCommerce
Last Modified: September 30, 2020


WooCommerce remove tax for user

Today we talk about how in WooCommerce remove tax for user. We will remove the tax on basis of the user id or user groups. Now, let’s start with our example.

add_filter( 'wc_tax_enabled',  'custom_enable_tax' , 1, 2 );
function custom_enable_tax(){
   $user = wp_get_current_user(); //get current user
   if( '20' == $user->ID ){
      return false;//remove tax for current user on basis of id
   }
   if( 'customer' == $user->roles[0] ){
     return false; //remove tax for current user on basis of user group
   }
  return true,
}
Author: Qaisar Satti
Category: WooCommerce
Last Modified: September 30, 2020


WooCommere remove tax for product

Today we talk about WooCommerce remove tax for product. Sometime in the scenario, you have to remove the tax bases on some condition. In the below example, I will explain how can you achieve this functionality.

add_filter( 'woocommerce_product_is_taxable' , 'product_product_custom_tax_status' , 10 , 2);
function product_product_custom_tax_status( $product_status , $product ){
    //return true to enable Tax and false to disable tax
    if( '20' == $product->get_id() ){
        return false;
    }else {
       return true;
    }
}
Author: Qaisar Satti
Category: WooCommerce
Last Modified: September 30, 2020


Pages:12