I have added this:
if ( ! class_exists( ‘WPC_UserID_Condition’ ) ) {
class WPC_UserID_Condition extends WPC_Condition {
public function __construct() {
$this->name = __( 'User ID', 'wpc-conditions' );
$this->slug = __( 'userid', 'wpc-conditions' );
$this->group = __( 'User', 'wpc-conditions' );
$this->description = __( 'Compare against the user id', 'wpc-conditions' );
parent::__construct();
}
public function match( $match, $operator, $value ) {
$value = $this->get_value( $value );
$user_id = $this->get_compare_value();
if ( '==' == $operator ) :
$match = ( array_key_exists( $value, $user_id ) );
elseif ( '!=' == $operator ) :
$match = ( ! array_key_exists( $value, $user_id ) );
endif;
return $match;
}
public function get_compare_value() {
if ( is_user_logged_in() ) {
//global $current_user;
return get_current_user_id();
} else {
return 0;
}
}
public function get_available_operators() {
$operators = parent::get_available_operators();
unset( $operators['>='] );
unset( $operators['<='] );
return $operators;
}
public function get_value_field_args() {
$users = get_users();
$list = array();
$count = 0;
foreach ($users as $user) {
$list[$count]['userid'] = $user->ID;
$list[$count]['username'] = $user->display_name;
$count++;
}
$field_args = array(
'type' => 'text',
'custom_attributes' => array(
'data-placeholder' => __( 'Buscar cliente', 'wp-conditions' ),
),
'class' => array( 'wpc-value', 'wc-users-search' ),
'options' => wp_list_pluck( $list, 'username', 'userid' ),
);
// Should be a select field in WC 2.7+
if ( version_compare( WC()->version, '2.7', '>=' ) ) {
$field_args['type'] = 'select';
}
return $field_args;
}
}
}
add_filter( ‘wp-conditions\registered_conditions’, ‘cvw_conditions’ );
function cvw_conditions($conditions) {
array_push($conditions, new WPC_UserID_Condition());
return $conditions;
}
add_filter( ‘wafs_conditions’, ‘cvw_get_conditions’ );
function cvw_get_conditions($conditions) {
$conditions[‘Personalizado’] = array(
‘userid’ => __( ‘User ID’, ‘woocommerce-advanced-free-shipping’ ),
);
return $conditions;
}
I can add the condition. But it’s not applied in checkout.