Server IP : 66.29.132.122 / Your IP : 18.191.42.234 Web Server : LiteSpeed System : Linux business142.web-hosting.com 4.18.0-553.lve.el8.x86_64 #1 SMP Mon May 27 15:27:34 UTC 2024 x86_64 User : admazpex ( 531) PHP Version : 7.2.34 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /var/softaculous/sitepad/editor/site-data/plugins/kkart-pro/includes/ |
Upload File : |
<?php /** * Kkart Order Item Functions * * Functions for order specific things. * * @package Kkart\Functions * @version 3.4.0 */ defined( 'ABSPATH' ) || exit; /** * Add a item to an order (for example a line item). * * @param int $order_id Order ID. * @param array $item_array Items list. * * @throws Exception When `KKART_Data_Store::load` validation fails. * @return int|bool Item ID or false */ function kkart_add_order_item( $order_id, $item_array ) { $order_id = absint( $order_id ); if ( ! $order_id ) { return false; } $defaults = array( 'order_item_name' => '', 'order_item_type' => 'line_item', ); $item_array = wp_parse_args( $item_array, $defaults ); $data_store = KKART_Data_Store::load( 'order-item' ); $item_id = $data_store->add_order_item( $order_id, $item_array ); $item = KKART_Order_Factory::get_order_item( $item_id ); do_action( 'kkart_new_order_item', $item_id, $item, $order_id ); return $item_id; } /** * Update an item for an order. * * @since 2.2 * @param int $item_id Item ID. * @param array $args Either `order_item_type` or `order_item_name`. * * @throws Exception When `KKART_Data_Store::load` validation fails. * @return bool True if successfully updated, false otherwise. */ function kkart_update_order_item( $item_id, $args ) { $data_store = KKART_Data_Store::load( 'order-item' ); $update = $data_store->update_order_item( $item_id, $args ); if ( false === $update ) { return false; } do_action( 'kkart_update_order_item', $item_id, $args ); return true; } /** * Delete an item from the order it belongs to based on item id. * * @param int $item_id Item ID. * * @throws Exception When `KKART_Data_Store::load` validation fails. * @return bool */ function kkart_delete_order_item( $item_id ) { $item_id = absint( $item_id ); if ( ! $item_id ) { return false; } $data_store = KKART_Data_Store::load( 'order-item' ); do_action( 'kkart_before_delete_order_item', $item_id ); $data_store->delete_order_item( $item_id ); do_action( 'kkart_delete_order_item', $item_id ); return true; } /** * Kkart Order Item Meta API - Update term meta. * * @param int $item_id Item ID. * @param string $meta_key Meta key. * @param string $meta_value Meta value. * @param string $prev_value Previous value (default: ''). * * @throws Exception When `KKART_Data_Store::load` validation fails. * @return bool */ function kkart_update_order_item_meta( $item_id, $meta_key, $meta_value, $prev_value = '' ) { $data_store = KKART_Data_Store::load( 'order-item' ); if ( $data_store->update_metadata( $item_id, $meta_key, $meta_value, $prev_value ) ) { KKART_Cache_Helper::invalidate_cache_group( 'object_' . $item_id ); // Invalidate cache. return true; } return false; } /** * Kkart Order Item Meta API - Add term meta. * * @param int $item_id Item ID. * @param string $meta_key Meta key. * @param string $meta_value Meta value. * @param bool $unique If meta data should be unique (default: false). * * @throws Exception When `KKART_Data_Store::load` validation fails. * @return int New row ID or 0. */ function kkart_add_order_item_meta( $item_id, $meta_key, $meta_value, $unique = false ) { $data_store = KKART_Data_Store::load( 'order-item' ); $meta_id = $data_store->add_metadata( $item_id, $meta_key, $meta_value, $unique ); if ( $meta_id ) { KKART_Cache_Helper::invalidate_cache_group( 'object_' . $item_id ); // Invalidate cache. return $meta_id; } return 0; } /** * Kkart Order Item Meta API - Delete term meta. * * @param int $item_id Item ID. * @param string $meta_key Meta key. * @param string $meta_value Meta value (default: ''). * @param bool $delete_all Delete all meta data, defaults to `false`. * * @throws Exception When `KKART_Data_Store::load` validation fails. * @return bool */ function kkart_delete_order_item_meta( $item_id, $meta_key, $meta_value = '', $delete_all = false ) { $data_store = KKART_Data_Store::load( 'order-item' ); if ( $data_store->delete_metadata( $item_id, $meta_key, $meta_value, $delete_all ) ) { KKART_Cache_Helper::invalidate_cache_group( 'object_' . $item_id ); // Invalidate cache. return true; } return false; } /** * Kkart Order Item Meta API - Get term meta. * * @param int $item_id Item ID. * @param string $key Meta key. * @param bool $single Whether to return a single value. (default: true). * * @throws Exception When `KKART_Data_Store::load` validation fails. * @return mixed */ function kkart_get_order_item_meta( $item_id, $key, $single = true ) { $data_store = KKART_Data_Store::load( 'order-item' ); return $data_store->get_metadata( $item_id, $key, $single ); } /** * Get order ID by order item ID. * * @param int $item_id Item ID. * * @throws Exception When `KKART_Data_Store::load` validation fails. * @return int */ function kkart_get_order_id_by_order_item_id( $item_id ) { $data_store = KKART_Data_Store::load( 'order-item' ); return $data_store->get_order_id_by_order_item_id( $item_id ); }