PluginProbe
Packeta / 1.6.4
Packeta v1.6.4
2.3.2 2.3.1 trunk 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.3.0 1.3.1 1.3.2 1.4 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 All 56 releases
packeta / src / Packetery / Module / ProductCategory / Entity.php

Entity.php in Packeta 1.6.4, at src/Packetery/Module/ProductCategory/Entity.php

84 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Product category entity.
4 *
5 * @package Packetery
6 */
7
8 declare( strict_types=1 );
9
10
11 namespace Packetery\Module\ProductCategory;
12
13 /**
14 * Class Entity
15 *
16 * @package Packetery
17 */
18 class Entity {
19
20 public const META_DISALLOWED_SHIPPING_RATES = 'packetery_disallowed_shipping_rates_by_cat';
21 public const TAXONOMY_NAME = 'product_cat';
22
23 /**
24 * Category.
25 *
26 * @var \WP_Term
27 */
28 private $category;
29
30 /**
31 * Entity constructor.
32 *
33 * @param \WP_term $category Category.
34 */
35 public function __construct( \WP_term $category ) {
36 $this->category = $category;
37 }
38
39 /**
40 * Create instance from term ID.
41 *
42 * @param int $termId Term ID.
43 *
44 * @return static
45 */
46 public static function fromTermId( int $termId ): self {
47 $product = get_term( $termId );
48
49 return new self( $product );
50 }
51
52 /**
53 * Disallowed carrier choices.
54 *
55 * @return array
56 */
57 public function getDisallowedShippingRateChoices(): array {
58 $choices = get_term_meta( $this->category->term_id, self::META_DISALLOWED_SHIPPING_RATES, true );
59 if ( ! is_array( $choices ) ) {
60 return [];
61 }
62
63 return $choices;
64 }
65
66 /**
67 * Disallowed carrier choices.
68 *
69 * @return array
70 */
71 public function getDisallowedShippingRateIds(): array {
72 return array_keys( $this->getDisallowedShippingRateChoices() );
73 }
74
75 /**
76 * Gets product ID.
77 *
78 * @return int
79 */
80 public function getId(): int {
81 return $this->category->term_id;
82 }
83 }
84