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

WooCommerce get comments by user id

Today we talk about WooCommerce or WordPress get comments by user id programmatically. In this tutorial, We focus on how to get user comments by using user id.

Let’s start with our example.

 $commentArg = array(
    'user_id' => 25,
         
    );
$comments = get_comments( $commentArg );
    if($comments){
      foreach($comments as $commentData){
        print_r($commentData);   
            }
                }
Author: Qaisar Satti
Last Modified: July 14, 2021


WooCommerce get comments by a user email

Today we talk about WooCommerce or WordPress get comments by a user email programmatically. In this tutorial, We focus on how to get user comments by using user email.

Let’s start with our example.

 $commentArg = array(
    'author_email' => $email,
         
    );
$comments = get_comments( $commentArg );
    if($comments){
      foreach($comments as $commentData){
        print_r($commentData);   
            }
                }
Author: Qaisar Satti
Last Modified: July 14, 2021


WooCommerce get an order by user id

Today we talk about WooCommerce or WordPress get an order by user id programmatically. In this tutorial, We focus on how to get user orders by using user id.

Let’s start with our example.

 $orderArg = array(
    'customer_id' => 23,
    'limit' => -1,
    'orderby' => 'date',
        'order' => 'DESC',
    );
$orders = wc_get_orders($orderArg);
if($orders){
  foreach ($orders as  $orderData) {
                print_r($orderData);
         }
}
Author: Qaisar Satti
Last Modified: July 14, 2021


WooCommerce get order by user email

Today we talk about WooCommerce or WordPress get an order by user email programmatically. In this tutorial, We focus on how to get user orders by using the user email.

Let’s start with our example.

 $orderArg = array(
    'customer' => $email,
    'limit' => -1,
    );
$orders = wc_get_orders($orderArg);
if($orders){
  foreach ($orders as  $orderData) {
                print_r($orderData);
         }
}
Author: Qaisar Satti
Last Modified: July 14, 2021


WooCommerce hide add to cart on shop page

Today we talk about WooCommerce or WordPress hide or remove add to cart on shop page programmatically. In this tutorial, We focus on how to hide/remove add to cart on the shop page.

Let’s start with our example.

add_action( 'woocommerce_after_shop_loop_item', 'qaisar_satti_remove_addtocart', 1 );

function qaisar_satti_remove_addtocart() {
  remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart');
}

If you want check with only the category listing page and shop page. You can use the following check.

     if( is_product_category() || is_shop()) {
      remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart');
     }
Author: Qaisar Satti
Last Modified: July 14, 2021


WooCommerce Select Variations on Shop Page

Today we talk about WooCommerce or WordPress select variation on shop page programmatically. In this tutorial, We focus on how to show select/dropdown on the shop page. It will be easier for customers to add to the cart with variations from the shop page. It will eliminate the step of the go-to single page and add to the cart from there.

Let’s start with our example.

   add_action('woocommerce_before_shop_loop', 'qaisar_satti_variations_dropdown');

function qaisar_satti_variations_dropdown() {
  remove_action('woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart' ); // remove already add to cart
  add_action('woocommerce_after_shop_loop_item', 'woocommerce_template_single_add_to_cart', 50 );// add sigle page add to cart
}
Author: Qaisar Satti
Last Modified: July 14, 2021


WooCommerce get all products

Today we talk about WooCommerce or WordPress get all products programmatically. In this tutorial, We focus on how to get all product data. In this example, we focus on getting all product information, information like product status, product type, product id, product title, and product price. You can use the following method to get all product wc_get_products. You can filter status to get products that are published and use limit filter -1 to get all the products.

Let’s start with our example.

$products = wc_get_products( array( 'status' => 'publish', 'limit' => -1 ) );

foreach ( $products as $product ){ 
    echo  $product->get_status();  // Product status
    echo  $product->get_type();  // Product type
    echo  $product->get_id();    // Product ID
    echo  $product->get_title(); // Product title
    echo  $product->get_slug(); // Product slug
    echo  $product->get_price(); // Product price
    echo  $product->get_catalog_visibility(); // Product visibility
    echo  $product->get_stock_status(); // Product stock status
    // product date information
    echo $product->get_date_created()->date('Y-m-d H:i:s');
    echo $product->get_date_modified()->date('Y-m-d H:i:s');
}
Author: Qaisar Satti
Last Modified: July 14, 2021


Pages:123456