__( 'AgeWallet', 'agewallet-oidc-client' ), 'target' => 'agewallet_product_data', 'class' => array(), 'priority' => 80, ); return $tabs; } /** * The four Age verification choices, in the order shown, each with the values it saves: * the product's regulated status, and the page's force-restrict and force-exclude flags. * * @return array */ public static function choices() { return array( 'follow' => array( 'label' => __( 'Follow store rules', 'agewallet-oidc-client' ), 'desc' => __( 'Viewing follows your Content Guarding rules. Buying follows your Checkout gating rule, including this product\'s categories and tags.', 'agewallet-oidc-client' ), 'status' => 'not_regulated', 'restrict' => false, 'exclude' => false, ), 'view_and_buy' => array( 'label' => __( 'Require verification to view and buy', 'agewallet-oidc-client' ), 'desc' => __( 'The product page is gated, and shoppers must verify their age before buying.', 'agewallet-oidc-client' ), 'status' => 'regulated', 'restrict' => true, 'exclude' => false, ), 'buy_only' => array( 'label' => __( 'Require verification to buy only', 'agewallet-oidc-client' ), 'desc' => __( 'The page stays open. Shoppers must verify their age before buying.', 'agewallet-oidc-client' ), 'status' => 'regulated', 'restrict' => false, 'exclude' => false, ), 'never' => array( 'label' => __( 'Never require verification', 'agewallet-oidc-client' ), 'desc' => __( 'The page is open and shoppers can buy without verifying, whatever your rules say.', 'agewallet-oidc-client' ), 'status' => 'override_not_regulated', 'restrict' => false, 'exclude' => true, ), ); } /** * The choice a product's saved values amount to: a key of choices(), or 'custom' when the * saved regulated status, force-restrict and force-exclude flags match none of them. * * @param int $post_id * @return string */ public static function choice_for_product( $post_id ) { $saved = self::saved_values( $post_id ); foreach ( self::choices() as $key => $choice ) { if ( $choice['status'] === $saved['status'] && $choice['restrict'] === $saved['restrict'] && $choice['exclude'] === $saved['exclude'] ) { return $key; } } return 'custom'; } /** * A product's saved values: its regulated status ('not_regulated' when nothing is saved) * and whether the page's force-restrict and force-exclude flags are on. * * @param int $post_id * @return array{status: string, restrict: bool, exclude: bool} */ private static function saved_values( $post_id ) { return array( 'status' => AgeWallet_WooCommerce::product_regulated_status( (int) $post_id ), 'restrict' => '1' === get_post_meta( $post_id, AgeWallet_Gating_Manager::META_KEY_FORCE_RESTRICT, true ), 'exclude' => '1' === get_post_meta( $post_id, AgeWallet_Gating_Manager::META_KEY_FORCE_EXCLUDE, true ), ); } /** * The Custom choice's description: the saved values named, for a product whose values * match no choice. * * @param int $post_id * @return string */ private static function custom_description( $post_id ) { $saved = self::saved_values( $post_id ); if ( $saved['restrict'] && $saved['exclude'] ) { $page = __( 'Require age verification and Exclude from age verification both on', 'agewallet-oidc-client' ); } elseif ( $saved['restrict'] ) { $page = __( 'Require age verification on', 'agewallet-oidc-client' ); } elseif ( $saved['exclude'] ) { $page = __( 'Exclude from age verification on', 'agewallet-oidc-client' ); } else { $page = __( 'no page setting', 'agewallet-oidc-client' ); } if ( 'regulated' === $saved['status'] ) { $buying = __( 'shoppers verify to buy', 'agewallet-oidc-client' ); } elseif ( 'override_not_regulated' === $saved['status'] ) { $buying = __( 'shoppers never verify to buy', 'agewallet-oidc-client' ); } else { $buying = __( 'buying inherits categories and tags', 'agewallet-oidc-client' ); } /* translators: 1: the page setting, 2: the buying setting */ return sprintf( __( 'Saved settings: %1$s; %2$s. Pick a choice above to replace them.', 'agewallet-oidc-client' ), $page, $buying ); } /** * The hint's two lines for a product: whether its page is gated by the page protection * rules (AgeWallet_Gating_Manager::should_restrict_content() for the product), and whether * shoppers verify before buying it (AgeWallet_WooCommerce::product_requires_verification() * and the Checkout gating rule). * * @param int $post_id * @return string[] */ private static function hint_lines( $post_id ) { $gated = class_exists( 'AgeWallet_Gating_Manager' ) && AgeWallet_Gating_Manager::instance()->should_restrict_content( (int) $post_id, false ); $lines = array( $gated ? __( 'This page is gated by your Content Guarding rules.', 'agewallet-oidc-client' ) : __( 'This page is open.', 'agewallet-oidc-client' ), ); if ( ! AgeWallet_WooCommerce::checkout_gating_enabled() ) { $lines[] = __( 'Checkout gating is off, so shoppers don\'t verify to buy.', 'agewallet-oidc-client' ); } elseif ( function_exists( 'wc_get_product' ) && AgeWallet_WooCommerce::product_requires_verification( wc_get_product( $post_id ) ) ) { $lines[] = __( 'Shoppers verify before buying this product.', 'agewallet-oidc-client' ); } else { $lines[] = __( 'Shoppers can buy this product without verifying.', 'agewallet-oidc-client' ); } return $lines; } /** * WC product-data-panel action: render the Age verification radios and the hint. */ public function render_product_data_panel() { global $post; $post_id = $post ? (int) $post->ID : 0; $current = $post_id ? self::choice_for_product( $post_id ) : 'follow'; $options = array(); foreach ( self::choices() as $key => $choice ) { $options[ $key ] = array( 'label' => $choice['label'], 'desc' => $choice['desc'] ); } if ( 'custom' === $current ) { $options['custom'] = array( 'label' => __( 'Custom', 'agewallet-oidc-client' ), 'desc' => self::custom_description( $post_id ), ); } $hint = $post_id ? self::hint_lines( $post_id ) : array(); ?>

term_id, AgeWallet_WooCommerce::META_KEY_TERM_REGULATED, true ); ?> />