| 1 |
<?php |
| 2 |
/** |
| 3 |
* WCPOS Store Functions. |
| 4 |
* |
| 5 |
* Functions for store specific things. |
| 6 |
* |
| 7 |
* @package WCPOS\WooCommercePOS |
| 8 |
*/ |
| 9 |
|
| 10 |
\defined( 'ABSPATH' ) || exit; |
| 11 |
|
| 12 |
use WCPOS\WooCommercePOS\Abstracts\Store; |
| 13 |
|
| 14 |
/* |
| 15 |
* Standard way of retrieving stores based on certain parameters. |
| 16 |
* |
| 17 |
* This function should be used for store retrieval so that we have a data agnostic |
| 18 |
* way to get a list of stores. |
| 19 |
* |
| 20 |
* @since 1.4.0 |
| 21 |
* |
| 22 |
* @param array $args Array of args. |
| 23 |
* @return array|stdClass Number of pages and an array of product objects if |
| 24 |
* paginate is true, or just an array of values. |
| 25 |
*/ |
| 26 |
if ( ! \function_exists( 'wcpos_get_stores' ) ) { |
| 27 |
/** |
| 28 |
* Get stores based on certain parameters. |
| 29 |
* |
| 30 |
* @param array $args Array of args. |
| 31 |
* @return array |
| 32 |
*/ |
| 33 |
function wcpos_get_stores( $args = array() ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound |
| 34 |
$store = new Store(); |
| 35 |
|
| 36 |
return apply_filters( 'woocommerce_pos_get_stores', array( $store ), $args ); |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
/* |
| 41 |
* Main function for returning store. |
| 42 |
* |
| 43 |
* This function should only be called after 'init' action is finished, as there might be taxonomies that are getting |
| 44 |
* registered during the init action. |
| 45 |
* |
| 46 |
* @since 1.4.0 |
| 47 |
* |
| 48 |
* @param mixed $the_store Post object or post ID of the product. |
| 49 |
* @param array $args Optional lookup args. |
| 50 |
* @return Store|null|false |
| 51 |
*/ |
| 52 |
if ( ! \function_exists( 'wcpos_get_store' ) ) { |
| 53 |
/** |
| 54 |
* Main function for returning store. |
| 55 |
* |
| 56 |
* @param mixed $the_store Post object or post ID of the product. |
| 57 |
* @param array $args Optional lookup args. |
| 58 |
* @return Store|null|false |
| 59 |
*/ |
| 60 |
function wcpos_get_store( $the_store = false, array $args = array() ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound |
| 61 |
$store = new Store(); |
| 62 |
|
| 63 |
return apply_filters( 'woocommerce_pos_get_store', $store, $the_store, $args ); |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
/* |
| 68 |
* Helper to get the store name by ID. |
| 69 |
* |
| 70 |
* This function should only be called after 'init' action is finished, as there might be taxonomies that are getting |
| 71 |
* registered during the init action. |
| 72 |
* |
| 73 |
* @since 1.4.0 |
| 74 |
* |
| 75 |
* @param mixed $the_store Post object or post ID of the product. |
| 76 |
* @param array $args Optional lookup args. |
| 77 |
* @return Store|null|false |
| 78 |
*/ |
| 79 |
if ( ! \function_exists( 'wcpos_get_store_name' ) ) { |
| 80 |
/** |
| 81 |
* Helper to get the store name by ID. |
| 82 |
* |
| 83 |
* @param mixed $the_store Post object or post ID of the product. |
| 84 |
* @param array $args Optional lookup args. |
| 85 |
* @return string |
| 86 |
*/ |
| 87 |
function wcpos_get_store_name( $the_store = false, array $args = array() ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound |
| 88 |
$store = wcpos_get_store( $the_store, $args ); |
| 89 |
|
| 90 |
if ( ! \is_object( $store ) || ! \method_exists( $store, 'get_name' ) ) { |
| 91 |
return ''; |
| 92 |
} |
| 93 |
|
| 94 |
return $store->get_name(); |
| 95 |
} |
| 96 |
} |
| 97 |
|