Last active
December 22, 2023 20:43
-
-
Save Lonsdale201/fc843375b9a811255c7de0ff3a4255b6 to your computer and use it in GitHub Desktop.
JetEngine Dynamic Visibility modul - WooCommerce Points and rewards - Equal or greater
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// place the code in the child theme functions.php or a custom code snippets plugin. | |
// Dont forget! This code is for the WooCommerce Points and Rewards plugin, so if it is not installed and activated, | |
// you will not be able to use this condition! | |
// https://woo.com/products/woocommerce-points-and-rewards/ | |
// Go to you block, widget container etc, open the Dynamic Visibility modul, and scroll down in the list, | |
// you will see a new category: Woo Points and Rewards | |
// this visibility only work for logged-in users. You can use the value field, to define the points. | |
// example : select the new Current user Equal or greater condition | |
// in the value field Enter the point amount. This visibility will check if the current user points equal or greater | |
// and based on your preferences will do the job. | |
add_action( 'jet-engine/modules/dynamic-visibility/conditions/register', function( $conditions_manager ) { | |
class WC_Points_Rewards_Current_User_Equal_Or_More extends \Jet_Engine\Modules\Dynamic_Visibility\Conditions\Base { | |
public function get_id() { | |
return 'wc-points-rewards-current-user-equal-or-more'; | |
} | |
public function get_name() { | |
return __( 'Current User Points Equal Or greater', 'jet-engine' ); | |
} | |
public function get_group() { | |
return 'Woo Points and Rewards'; | |
} | |
public function check( $args = array() ) { | |
if ( !is_user_logged_in() ) { | |
return false; | |
} | |
if ( ! class_exists( 'WC_Points_Rewards_Manager' ) ) { | |
return false; | |
} | |
$user_id = get_current_user_id(); | |
$user_points = WC_Points_Rewards_Manager::get_users_points( $user_id ); | |
$required_points = isset( $args['value'] ) ? intval( $args['value'] ) : 0; | |
$type = isset( $args['type'] ) ? $args['type'] : 'show'; | |
$meets_condition = $user_points >= $required_points; | |
if ( 'hide' === $type ) { | |
return !$meets_condition; | |
} else { | |
return $meets_condition; | |
} | |
} | |
public function is_for_fields() { | |
return false; | |
} | |
public function need_value_detect() { | |
return true; | |
} | |
} | |
$conditions_manager->register_condition( new WC_Points_Rewards_Current_User_Equal_Or_More() ); | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment