Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

query products by category woocommerce

$args = array(
   'post_type'             => 'product',
   'post_status'           => 'publish',
   'ignore_sticky_posts'   => 1,
   'posts_per_page'        => '12',
   'tax_query'             => array(
        array(
            'taxonomy'  => 'product_cat',
            'field'     => 'term_id',
            'terms'     => array('40'),
            'operator'  => 'IN',
        )
   )
);

$loop = new WP_Query( $args );
Comment

query orders by products woocommerce

/**
 * Get All orders IDs for a given product ID.
 *
 * @param  integer  $product_id (required)
 * @param  array    $order_status (optional) Default is 'wc-completed'
 *
 * @return array
 */
function get_orders_ids_by_product_id( $product_id, $order_status = array( 'wc-completed' ) ){
    global $wpdb;

    $results = $wpdb->get_col("
        SELECT order_items.order_id
        FROM {$wpdb->prefix}woocommerce_order_items as order_items
        LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta ON order_items.order_item_id = order_item_meta.order_item_id
        LEFT JOIN {$wpdb->posts} AS posts ON order_items.order_id = posts.ID
        WHERE posts.post_type = 'shop_order'
        AND posts.post_status IN ( '" . implode( "','", $order_status ) . "' )
        AND order_items.order_item_type = 'line_item'
        AND order_item_meta.meta_key = '_product_id'
        AND order_item_meta.meta_value = '$product_id'
    ");

    return $results;
}
Comment

PREVIOUS NEXT
Code Example
Typescript :: check if object exists in s3 bucket laravel 
Typescript :: DAX check if value exists in another table 
Typescript :: echarts cdn 
Typescript :: amcharts angular universal 
Typescript :: typescript slice string 
Typescript :: replace multiple elements in a list python 
Typescript :: Catch clause variable cannot have a type annotation. 
Typescript :: c# copy the elements of a list to another list 
Typescript :: Duplicate function implementation.ts(2393) 
Typescript :: how to add an element to a Typescript array 
Typescript :: how long does it take to learn typescript 
Typescript :: go through each element of a dictionary typescript 
Typescript :: how to create empty object typescript 
Typescript :: Contract in ethers.js 
Typescript :: property decorator typescript constructor 
Typescript :: mongodb update all items in array 
Typescript :: interact with blockchain from nextjs 
Typescript :: typescript keyof typeof 
Typescript :: how to add multiple arguments in discord commands rewrite 
Typescript :: content script matches all 
Typescript :: react-native use typescript 
Typescript :: when a vector in c++ is resized what happens to the elements of the vector 
Typescript :: [(ngModel)] input error 
Typescript :: tar: refusing to read archive contents from terminal (missing -f option?) tar: error is not recoverable: exiting now 
Typescript :: laravel no tests executed 
Typescript :: file reader with promise 
Typescript :: angular validations 
Typescript :: json to ts type 
Typescript :: get number of digits in an integer python without converting to string 
Typescript :: find elements by xpath with matching text 
ADD CONTENT
Topic
Content
Source link
Name
4+3 =