PluginProbe
WCPOS – Point of Sale (POS) plugin for WooCommerce / 1.9.16
WCPOS – Point of Sale (POS) plugin for WooCommerce v1.9.16
1.10.19 1.10.18 1.10.17 1.10.16 1.10.15 1.10.13 1.10.14 1.10.12 1.10.11 1.10.10 1.10.9 1.10.8 untagged-3d9b7ccddc54df87c672 1.10.7 1.10.6 1.10.5 1.10.3 1.10.4 1.10.2 1.10.1 1.10.0 1.9.17 1.9.15 1.9.16 1.9.14 All 163 releases
woocommerce-pos / includes / API / Traits / Product_Helpers.php

Product_Helpers.php in WCPOS – Point of Sale (POS) plugin for WooCommerce 1.9.16, at includes/API/Traits/Product_Helpers.php

79 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Product_Helpers.
4 *
5 * @package WCPOS\WooCommercePOS
6 */
7
8 namespace WCPOS\WooCommercePOS\API\Traits;
9
10 use WC_Product;
11 use WC_Product_Variation;
12 use WCPOS\WooCommercePOS\Logger;
13
14 trait Product_Helpers {
15 /**
16 * Get custom barcode postmeta.
17 *
18 * @param WC_Product|WC_Product_Variation $object The product object.
19 *
20 * @return string
21 */
22 public function wcpos_get_barcode( $object ) {
23 $barcode_field = $this->wcpos_get_barcode_field();
24
25 if ( '_sku' === $barcode_field ) {
26 return $object->get_sku();
27 }
28 if ( '_global_unique_id' === $barcode_field ) {
29 return $object->get_global_unique_id();
30 }
31
32 return $object->get_meta( $barcode_field );
33 }
34
35 /**
36 * Get barcode field from settings.
37 *
38 * @return string
39 */
40 public function wcpos_get_barcode_field() {
41 $barcode_field = woocommerce_pos_get_settings( 'general', 'barcode_field' );
42
43 // Check for WP_Error.
44 if ( is_wp_error( $barcode_field ) ) {
45 Logger::log( 'Error retrieving barcode_field: ' . $barcode_field->get_error_message() );
46
47 return '';
48 }
49
50 // Check for non-string values.
51 if ( ! \is_string( $barcode_field ) ) {
52 Logger::log( 'Unexpected data type for barcode_field. Expected string, got: ' . \gettype( $barcode_field ) );
53
54 return '';
55 }
56
57 return $barcode_field;
58 }
59
60 /**
61 * Get barcode field from settings.
62 *
63 * @return bool
64 */
65 public function wcpos_pos_only_products_enabled() {
66 $pos_only_products_enabled = woocommerce_pos_get_settings( 'general', 'pos_only_products' );
67
68 // Check for WP_Error.
69 if ( is_wp_error( $pos_only_products_enabled ) ) {
70 Logger::log( 'Error retrieving pos_only_products: ' . $pos_only_products_enabled->get_error_message() );
71
72 return false;
73 }
74
75 // Make sure it's true, just in case there's a corrupt setting.
76 return true === $pos_only_products_enabled;
77 }
78 }
79