PluginProbe
Packeta / 1.2.6
Packeta v1.2.6
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 / Product / Entity.php

Entity.php in Packeta 1.2.6, at src/Packetery/Module/Product/Entity.php

89 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Product entity.
4 *
5 * @package Packetery\Module\Product
6 */
7
8 declare( strict_types=1 );
9
10
11 namespace Packetery\Module\Product;
12
13 /**
14 * Class Entity
15 *
16 * @package Packetery\Module\Product
17 */
18 class Entity {
19
20 public const META_AGE_VERIFICATION_18_PLUS = 'packetery_age_verification_18_plus';
21
22 /**
23 * Product.
24 *
25 * @var \WC_Product
26 */
27 private $product;
28
29 /**
30 * Entity constructor.
31 *
32 * @param \WC_Product $product Product.
33 */
34 public function __construct( \WC_Product $product ) {
35 $this->product = $product;
36 }
37
38 /**
39 * Creates instance using global variables.
40 *
41 * @return static
42 */
43 public static function fromGlobals(): self {
44 global $post;
45
46 return self::fromPostId( $post->ID );
47 }
48
49 /**
50 * Create instance from post ID.
51 *
52 * @param int|string $postId Post ID.
53 *
54 * @return static
55 */
56 public static function fromPostId( $postId ): self {
57 $product = wc_get_product( $postId );
58
59 return new self( $product );
60 }
61
62 /**
63 * Is product relevant for Packeta processing?
64 *
65 * @return bool
66 */
67 public function isPhysical(): bool {
68 return false === $this->product->is_virtual() && false === $this->product->is_downloadable();
69 }
70
71 /**
72 * Is age verification required?
73 *
74 * @return bool
75 */
76 public function isAgeVerification18PlusRequired(): bool {
77 return $this->product->get_meta( self::META_AGE_VERIFICATION_18_PLUS ) === '1';
78 }
79
80 /**
81 * Gets product ID.
82 *
83 * @return int
84 */
85 public function getId(): int {
86 return $this->product->get_id();
87 }
88 }
89