Skip to content

Instantly share code, notes, and snippets.

@Lonsdale201
Last active December 22, 2023 14:41
Show Gist options
  • Save Lonsdale201/fc0e520e5ca642cb9ca27f2302e7c30d to your computer and use it in GitHub Desktop.
Save Lonsdale201/fc0e520e5ca642cb9ca27f2302e7c30d to your computer and use it in GitHub Desktop.
JetEngine Dynamic Visibility modul - WooCommerce Points and rewards
// 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. Will Check if the points is more than 0
add_action( 'jet-engine/modules/dynamic-visibility/conditions/register', function( $conditions_manager ) {
class WC_Points_Rewards_Current_User_Have_Points extends \Jet_Engine\Modules\Dynamic_Visibility\Conditions\Base {
public function get_id() {
return 'wc-points-rewards-current-user-have-points';
}
public function get_name() {
return __( 'Current User Have Points', '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();
$points = WC_Points_Rewards_Manager::get_users_points( $user_id );
$has_points = ($points > 0);
$type = isset( $args['type'] ) ? $args['type'] : 'show';
if ( 'hide' === $type ) {
return !$has_points;
} else {
return $has_points;
}
}
public function is_for_fields() {
return false;
}
public function need_value_detect() {
return false;
}
}
$conditions_manager->register_condition( new WC_Points_Rewards_Current_User_Have_Points() );
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment