Dokan product manager

File: Manager.php
Namespace: WeDevs\Dokan\Product;
Location : dokan-lite\includes\Product\Manager.php

Product manager class. This class holds a lot of  methods that help to get and save information about vendor products.

Product manager class api #

  • Get all products form database according to database. #
dokan()->product->all( $args );
  • Get a single product object by the product id. #
$product = dokan()->product->get( $product_id );
  • Create a new product by all product information arguments as an array. #
$product_created = dokan()->product->create( $agrs = [] );
  • Create a new product by all product information arguments as an array. #
$product_update = dokan()->product->update( $agrs = [] );
  • Delete product by product id. #
$deleted_product = dokan()->product->delete( $product_id, true );
  • Get all featured products according to arguments. #
$all_featured = dokan()->product->featured( $args );
  • Get all latest products according to arguments. #
$all_latest = dokan()->product->latest($args );
  • Get all the best selling products according to arguments. #
$all_best_selling = dokan()->product->best_selling( $args );
  • Get all the top rated products according to arguments. #
$all_top_rated = dokan()->product->top_reated( $args );

Product manager class methods reference #

Method :  all ( array $args )

Description #
Get all products from the database. There are some default arguments by which you can get all the products. And this method is using WP_Query so you can also use any extra arguments to get your products.

Parameter #
$args 

(array)(optional) It’s optional but you can give parameters to customize.

  • post_type
    ( string ) default ‘product’
  • post_status
    ( array ) array of post status that you want default [ ‘publish’, ‘draft’, ‘pending’, ‘future’ ]
  • posts_per_page
    ( integer ) number of posts per request default -1, means all posts
  • orderby
    ( string ) default ‘post_date ID’
  • order
    ( string ) post order default ‘DESC’
  • paged
    ( integer ) default 1

Returns #
void

Usage #

$products = dokan()->product->all( $args );
print_r( $products );

Method :  get( int $product_id )

Description #
Get a single product object by the product id.

Parameter #
$product_id 
( integer ) product id is mandatory.

Returns #
( object ) product object.

Usage #

$product = dokan()->product->get( $product_id );
print_r( $product );

Method :  create( array $args = [] )

Description #
Create a new product by all product information arguments as an array.

Parameter #
$args 

( array ) product information as an array.

  • id
    ( integer ) ( optional ) product id
  • type
    ( string ) very important argument, default WC_Product_Simple. Basically this is the product type class name.
  • name
    ( string ) This is the post title and product name.
  • descripiton
    ( string ) This is the post content or product description.
  • short_description
    ( string ) This is the post excerpt or product short description.
  • status
    ( string ) This is the post status default ‘draft’
  • slug
    ( string ) This is the post slug or product slug.
  • menu_order
    ( integer ) menu order.
  • reviews_allowed
    ( string | boolean ) accepted arguments yes/no, true/false, 1/0
  • virtual
    ( string | boolean ) accepted arguments yes/no, true/false, 1/0
  • tax_status
    ( string ) accepted arguments taxable/shipping/none default ‘taxable’
  • catalog_visibility
    ( string ) catalog visibility option, accepted arguments hidden/visible/search/catalog
  • purchase_note
    ( string ) Product purchase note.
  • featured
    ( string | boolean ) accepted arguments yes/no, true/false, 1/0
  • sku
    ( string ) product sku text.
  • attributes
    ( array ) ( optional ) product attributes array.
    • id
      ( integer ) 0 for product label attributes. ID for global label attributes.
    • name
      ( string ) Attribute name.
    • options
      ( array ) attribute value or array of items ids/names.
    • position
      ( integer ) sort order
    • visible
      ( boolean ) If visible in frontend.
    • variation
      ( boolean ) If used for variations.
  • regular_price
    ( integer | float ) Product regular price
  • sale_price
    ( integer | float ) Product sale price.
  • date_on_sale_from
    ( string|integer|null ) $date UTC timestamp, or ISO 8601 DateTime. If the DateTime string has no timezone or offset, WordPress site timezone will be assumed. Null if their is no date.
  • date_on_sale_from_gmt
    ( string|integer|null ) $date UTC timestamp, or ISO 8601 DateTime. If the DateTime string has no timezone or offset, WordPress site timezone will be assumed. Null if their is no date.
  • date_on_sale_to
    ( string|integer|null ) $date UTC timestamp, or ISO 8601 DateTime. If the DateTime string has no timezone or offset, WordPress site timezone will be assumed. Null if their is no date.
  • date_on_sale_to_gmt
    ( string|integer|null ) $date UTC timestamp, or ISO 8601 DateTime. If the DateTime string has no timezone or offset, WordPress site timezone will be assumed. Null if their is no date.
  • parent_id
    ( integer ) ( optional ) Product parent id
  • sold_individually
    ( boolean ) $sold_individually Whether or not product is sold individually.
  • stock_status
    ( string ) Valid values are view / edit.
  • manage_stock
    ( boolean ) Whether or not manage stock is enabled.
  • backorders
    ( string ) valid options  ‘yes’, ‘no’ or ‘notify’.
  • stock_quantity
    ( float|null ) Product stock quantity.
  • upsell_ids
    ( array ) IDs from the up-sell products.
  • cross_sell_ids
    ( array ) IDs from the cross-sell products.
  • categories
    ( array ) Array of terms or product categories.
  • tags
    ( array ) Array of terms or product tags.
  • downloadable
    ( string | boolean ) accepted arguments yes/no, true/false, 1/0
  • downloads
    ( array  ) Downloads data.
  • download_limit
    ( int|string ) Product download limit.
  • download_expiry
    ( int|string ) Product download expiry.
  • external_url
    ( string ) Product url for external products.
  • button_text
    ( string ) Button text for external products.
  • grouped_products
    ( array )( optional ) children for a grouped product.
  • featured_image_id
    ( int|string ) Product image id.
  • gallery_image_ids
    ( array ) List of image ids.
  • meta_data
    ( array ) ( optional ) add meta data as key value pair.
  • date_created
    ( string|integer|null ) UTC timestamp, or ISO 8601 DateTime. If the DateTime string has no timezone or offset, WordPress site timezone will be assumed. Null if their is no date.
  • date_created_gmt
    ( string|integer|null ) UTC timestamp, or ISO 8601 DateTime. If the DateTime string has no timezone or offset, WordPress site timezone will be assumed. Null if their is no date.

Returns #
( object ) Product object.

Alternate function #
dokan_save_product( array $args = [] )
Arguments are the same as create method.

Usage #

$product_created = dokan()->product->create( $agrs = [] );
print_r( $product_created );

Method :  update( array $args = [] )

Description #
Create a new product by all product information arguments as an array.

Parameter #
$args 

( array ) product information as an array.

  • id
    ( integer ) ( required ) product id
  • type
    ( string ) very important argument, default WC_Product_Simple. Basically this is the product type class name.
  • name
    ( string ) This is the post title and product name.
  • descripiton
    ( string ) This is the post content or product description.
  • short_description
    ( string ) This is the post excerpt or product short description.
  • status
    ( string ) This is the post status default ‘draft’
  • slug
    ( string ) This is the post slug or product slug.
  • menu_order
    ( integer ) menu order.
  • reviews_allowed
    ( string | boolean ) accepted arguments yes/no, true/false, 1/0
  • virtual
    ( string | boolean ) accepted arguments yes/no, true/false, 1/0
  • tax_status
    ( string ) accepted arguments taxable/shipping/none default ‘taxable’
  • catalog_visibility
    ( string ) catalog visibility option, accepted arguments hidden/visible/search/catalog
  • purchase_note
    ( string ) Product purchase note.
  • featured
    ( string | boolean ) accepted arguments yes/no, true/false, 1/0
  • sku
    ( string ) product sku text.
  • attributes
    ( array ) ( optional ) product attributes array.
    • id
      ( integer ) 0 for product label attributes. ID for global label attributes.
    • name
      ( string ) Attribute name.
    • options
      ( array ) attribute value or array of items ids/names.
    • position
      ( integer ) sort order
    • visible
      ( boolean ) If visible in frontend.
    • variation
      ( boolean ) If used for variations.
  • regular_price
    ( integer | float ) Product regular price
  • sale_price
    ( integer | float ) Product sale price.
  • date_on_sale_from
    ( string|integer|null ) $date UTC timestamp, or ISO 8601 DateTime. If the DateTime string has no timezone or offset, WordPress site timezone will be assumed. Null if their is no date.
  • date_on_sale_from_gmt
    ( string|integer|null ) $date UTC timestamp, or ISO 8601 DateTime. If the DateTime string has no timezone or offset, WordPress site timezone will be assumed. Null if their is no date.
  • date_on_sale_to
    ( string|integer|null ) $date UTC timestamp, or ISO 8601 DateTime. If the DateTime string has no timezone or offset, WordPress site timezone will be assumed. Null if their is no date.
  • date_on_sale_to_gmt
    ( string|integer|null ) $date UTC timestamp, or ISO 8601 DateTime. If the DateTime string has no timezone or offset, WordPress site timezone will be assumed. Null if their is no date.
  • parent_id
    ( integer ) ( optional ) Product parent id
  • sold_individually
    ( boolean ) $sold_individually Whether or not product is sold individually.
  • stock_status
    ( string ) Valid values are view / edit.
  • manage_stock
    ( boolean ) Whether or not manage stock is enabled.
  • backorders
    ( string ) valid options  ‘yes’, ‘no’ or ‘notify’.
  • stock_quantity
    ( float|null ) Product stock quantity.
  • upsell_ids
    ( array ) IDs from the up-sell products.
  • cross_sell_ids
    ( array ) IDs from the cross-sell products.
  • categories
    ( array ) Array of terms or product categories.
  • tags
    ( array ) Array of terms or product tags.
  • downloadable
    ( string | boolean ) accepted arguments yes/no, true/false, 1/0
  • downloads
    ( array  ) Downloads data.
  • download_limit
    ( int|string ) Product download limit.
  • download_expiry
    ( int|string ) Product download expiry.
  • external_url
    ( string ) Product url for external products.
  • button_text
    ( string ) Button text for external products.
  • grouped_products
    ( array )( optional ) children for a grouped product.
  • featured_image_id
    ( int|string ) Product image id.
  • gallery_image_ids
    ( array ) List of image ids.
  • meta_data
    ( array ) ( optional ) add meta data as key value pair.
  • date_created
    ( string|integer|null ) UTC timestamp, or ISO 8601 DateTime. If the DateTime string has no timezone or offset, WordPress site timezone will be assumed. Null if their is no date.
  • date_created_gmt
    ( string|integer|null ) UTC timestamp, or ISO 8601 DateTime. If the DateTime string has no timezone or offset, WordPress site timezone will be assumed. Null if their is no date.

Returns #
( object ) Product object.

Usage #

$updated_product = dokan()->product->update( $agrs = [] );
print)r( $updated_product );

Method : delete( int $product_id, boolean $force )

Description #
Delete product by product id

Parameter #
$product_id
( integer )( required ) Product id or post id.

$force

Is delete forcely/permanently default true.

Returns #
( object ) deleted product object.

Usage #

$deleted = dokan()->product->delete( $product_id, true );
print_r( $deleted );

Description #
Get all featured products. Also you can add more meta query arguments for customization.

Returns #
( array )all featured products.

Usage #

$featured = dokan()->product->featured();
print_r( $featured );

Method : latest( array $args = [] )

Description #
Get all latest products. Also you can add more meta query arguments for customization.

Returns #
( array )all latest products.

Usage #

$latest = dokan()->product->latest();
$print_r( $latest );

Method : best_selling( array $args = [] )

Description #
Get all the best selling products. Also you can add more meta query arguments for customization.

Returns #
( array )all the best selling products.

Usage #

$all_best_selling = dokan()->product->best_selling();
print_r( $all_best_selling );

Method : top_rated( array $args = [] )

Description #
Get all the top rated products. Also you can add more meta query arguments for customization.

Returns #
( array )all the top rated products.

Usage #

$all_top_rated = dokan()->product->top_reated();
print_r( $all_top_rated );

Function reverences

Function : dokan_product_get_row_action( object $post )

Description #

Get a products row action linke view, edit, delete action and their url title etc.

Parameter #

$post 

( object ) single product object data.

Returns #

( array ) array of all actions.

Usage #

dokan_product_get_row_action( $post );

Function : dokan_get_vendor_by_product( object|id $product )

Description #

Get vendor information of a product.

Parameter #

$product 

( object|id ) single product object or id.

Returns #

( object|boolean ) vendor object or boolean.

Usage #

dokan_get_vendor_by_product( $product );

Leave a Reply

Your email address will not be published. Required fields are marked *