PluginProbe
Tiered Pricing Table for WooCommerce / 8.0.2
Tiered Pricing Table for WooCommerce v8.0.2
8.0.2 7.1.7 7.1.5 7.1.4 7.1.1 6.5.0 6.4.0 6.1.0 trunk 1.0 1.1 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.2.0 2.2.1 2.2.2 2.2.3 2.3.0 2.3.1 2.3.2 2.3.3 All 91 releases
tier-pricing-table / src / Addons / NonLoggedInUsers / Visibility / Admin / ProductVisibilityFields.php

ProductVisibilityFields.php in Tiered Pricing Table for WooCommerce 8.0.2, at src/Addons/NonLoggedInUsers/Visibility/Admin/ProductVisibilityFields.php

50 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php namespace TierPricingTable\Addons\NonLoggedInUsers\Visibility\Admin;
2
3 use TierPricingTable\Addons\NonLoggedInUsers\Visibility\VisibilityMeta;
4 use TierPricingTable\Addons\NonLoggedInUsers\Visibility\VisibilityRule;
5
6 /**
7 * "Who can see this product" in the product's Tiered Pricing tab (Additional Options).
8 */
9 class ProductVisibilityFields {
10
11 const NONCE = 'tpt_visibility_product';
12
13 public function __construct() {
14 add_action( 'tiered_pricing_table/admin/advance_product_options', array( $this, 'render' ) );
15 add_action( 'woocommerce_process_product_meta', array( $this, 'save' ) );
16 }
17
18 public function render( $productId ) {
19 $rule = VisibilityMeta::getProductRule( (int) $productId );
20
21 wp_nonce_field( self::NONCE, self::NONCE );
22
23 woocommerce_wp_select( array(
24 'id' => VisibilityMeta::PRODUCT_MODE,
25 'label' => __( 'Who can see this product', 'tier-pricing-table' ),
26 'options' => VisibilityMeta::getModeOptions( true ),
27 'value' => $rule['mode'],
28 'desc_tip' => true,
29 'description' => __( 'Hidden products leave the shop, search, related lists and menus, cannot be bought, and their page sends guests to the login page. Shop managers always see everything.', 'tier-pricing-table' ),
30 ) );
31
32 RoleChecklist::render( VisibilityMeta::PRODUCT_ROLES, $rule['roles'], VisibilityMeta::PRODUCT_MODE );
33 }
34
35 public function save( $productId ) {
36 if ( ! isset( $_POST[ self::NONCE ] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST[ self::NONCE ] ) ), self::NONCE ) ) {
37 return;
38 }
39
40 if ( ! current_user_can( 'edit_product', $productId ) ) {
41 return;
42 }
43
44 $mode = isset( $_POST[ VisibilityMeta::PRODUCT_MODE ] ) ? sanitize_key( wp_unslash( $_POST[ VisibilityMeta::PRODUCT_MODE ] ) ) : VisibilityRule::MODE_INHERIT;
45 $roles = isset( $_POST[ VisibilityMeta::PRODUCT_ROLES ] ) ? array_map( 'sanitize_key', (array) wp_unslash( $_POST[ VisibilityMeta::PRODUCT_ROLES ] ) ) : array();
46
47 VisibilityMeta::saveProductRule( (int) $productId, $mode, $roles );
48 }
49 }
50