1. Home
  2. Developers
  3. wpinv_update_item()

wpinv_update_item()

Introduction | Parameters | Examples

Introduction

Update an item.

wpinv_update_item( array $args = array(), bool $wp_error = false )

Item data will be updated for the value set in ‘ID’ parameter. It only updates data which are passed to $args array.

Parameters

$args

(array) (Required) An array of elements to update an item.

  • ID
    (int) (Required) The ‘ID’ of the item that needs to be updated.
  • type
    (string) (Optional) The item type.
    Default: ‘custom’
  • title
    (string) (Optional) The item title.
  • custom_id
    (string) (Optional) Any integer or non numeric id. Must be unique within item type.
    Default: item ID will be set after save.
  • price
    (float) (Optional) The item price.
    Default: ‘0.00’
  • status
    (string) (Optional) The item status. ‘publish’ => Published item, ‘pending’ => Pending item.
    Default: ‘pending’
  • custom_name
    (string) (Optional) Plural sub title for the item.
    Default: empty
  • custom_singular_name
    (string) (Optional) Singular sub title for the item.
    Default: empty
  • vat_rule
    (string) (Optional) VAT rule to apply if tax enabled. ‘digital’ => Digital item, ‘physical’ => Physical item.
    Default: ‘digital’
  • editable
    (bool) (Optional) Item editable from backend items page?
    Default: true
  • excerpt
    (string) (Optional) The item excerpt(short description).
    Default: empty
  • is_recurring
    (bool) (Optional) Whether to enable recurring feature for the item? Use 1 => Allow recurring or 0 => Don’t allow recurring.
    Default: 0
  • recurring_period
    (string) (Optional) Recurring time period. ‘D’ => Daily, ‘W’ => Weekly, ‘M’ => Monthly, ‘Y’ => Yearly.
    Default: ‘M’
  • recurring_interval
    (int) (Optional) Recurring interval. Integer number between 1 – 90.
    Default: 1
  • recurring_limit
    (int) (Optional) Recurring limit. 0 for recurring forever until cancelled.
    Default: 0
  • free_trial
    (bool) (Optional) Whether to enable free trial if recurring feature is enabled?
    Default: 0
  • trial_period
    (int) (Optional) Free trial time period. ‘D’ => Daily, ‘W’ => Weekly, ‘M’ => Monthly, ‘Y’ => Yearly.
    Default: ‘M’
  • trial_interval
    (int) (Optional) Free trial interval. Integer number between 1 – 90.
    Default: 1
$wp_error

(bool) (Optional) Whether to return a WP_Error on failure.

Default: false

Return

(int|object|WP_Error) The value 0 or WP_Error on failure. The WPInv_Item object on success.

Examples

Example 1:

Update an item with simple data. Following example will update only item title & item price.

$data = array(
    'ID'       => 2570,
    'title'    => __( 'Simple Item', 'textdomain' ),
    'price'    => '299.00',
 );
 
$item = wpinv_update_item( $data, true );

View at GitHub: https://github.com/AyeCode/wpinv-example/blob/master/items/update-item-simple.php

Example 2:

Update an item with advance data.

$data = array(
    'ID'                   => 2571,
    'type'                 => 'custom',
    'title'                => __( 'Advance Item', 'textdomain' ),
    'custom_id'            => 123457,
    'price'                => '49.00',
    'status'               => 'publish',
    'custom_name'          => 'Custom name',
    'custom_singular_name' => 'For Sale',
    'vat_rule'             => 'digital',
    'editable'             => true,
    'excerpt'              => __( 'This is my first item.', 'textdomain' ),
    'is_recurring'         => 1,
    'recurring_period'     => 'M',
    'recurring_interval'   => 1,
    'recurring_limit'      => 6,
    'free_trial'           => 1,
    'trial_period'         => 'M',
    'trial_interval'       => 1,
 );
 
$item = wpinv_update_item( $data, true );

View at GitHub: https://github.com/AyeCode/wpinv-example/blob/master/items/update-item-advanced.php

Was this helpful to you? Yes No