jetformbuilder
/
compatibility
/
woocommerce
/
methods
/
wc-product-modification
/
product-id-property.php
base-product-property.php
2 years ago
product-backorders-property.php
2 years ago
product-catalog-visibility-property.php
2 years ago
product-cross-sell-ids-property.php
2 years ago
product-date-on-sale-from-property.php
2 years ago
product-date-on-sale-to-property.php
2 years ago
product-date-property.php
2 years ago
product-description-property.php
2 years ago
product-featured-property.php
2 years ago
product-gallery-property.php
2 years ago
product-height-property.php
2 years ago
product-id-property.php
2 years ago
product-image-property.php
2 years ago
product-length-property.php
2 years ago
product-low-stock-amount-property.php
2 years ago
product-manage-stock-property.php
2 years ago
product-name-property.php
2 years ago
product-parent-property.php
2 years ago
product-regular-price-property.php
2 years ago
product-reviews-allowed-property.php
2 years ago
product-sale-price-property.php
2 years ago
product-short-description-property.php
2 years ago
product-sku-property.php
2 years ago
product-sold-individually-property.php
2 years ago
product-status-property.php
2 years ago
product-stock-quantity-property.php
2 years ago
product-stock-status-property.php
2 years ago
product-tax-class-property.php
2 years ago
product-tax-status-property.php
2 years ago
product-total-sales-property.php
2 years ago
product-upsell-ids-property.php
2 years ago
product-weight-property.php
2 years ago
product-width-property.php
2 years ago
save-action.php
2 years ago
trash-action.php
2 years ago
wc-product-modifier.php
2 years ago
product-id-property.php
43 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | namespace JFB_Compatibility\Woocommerce\Methods\Wc_Product_Modification; |
| 5 | |
| 6 | use Jet_Form_Builder\Actions\Methods\Abstract_Modifier; |
| 7 | use JFB_Modules\Actions_V2\Insert_Post\Properties\Post_Id_Property; |
| 8 | use Jet_Form_Builder\Exceptions\Action_Exception; |
| 9 | |
| 10 | // If this file is called directly, abort. |
| 11 | if ( ! defined( 'WPINC' ) ) { |
| 12 | die; |
| 13 | } |
| 14 | |
| 15 | class Product_Id_Property extends Post_Id_Property { |
| 16 | |
| 17 | /** |
| 18 | * @param string $key |
| 19 | * @param $value |
| 20 | * @param Abstract_Modifier $modifier |
| 21 | * |
| 22 | * @throws Action_Exception |
| 23 | */ |
| 24 | public function do_before( string $key, $value, Abstract_Modifier $modifier ) { |
| 25 | try { |
| 26 | $this->value = wc_get_product( $value ); |
| 27 | } catch ( \Exception $exception ) { |
| 28 | throw new Action_Exception( esc_html( $exception->getMessage() ) ); |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | public function get_product(): \WC_Product { |
| 33 | if ( ! is_null( $this->value ) ) { |
| 34 | return $this->value; |
| 35 | } |
| 36 | $this->value = new \WC_Product_Simple(); |
| 37 | |
| 38 | return $this->value; |
| 39 | } |
| 40 | |
| 41 | |
| 42 | } |
| 43 |