Hi Jeroen, thank you for your reply. I added the following code to functions.php as documented, but the points does not appear in the dropdown under Conditions. Do you know what the problem is?
/**
* Add condition to conditions list.
*
* @param array $conditions List of existing conditions.
* @return aray List of modified conditions.
*/
function was_conditions_add_points( $conditions ) {
// 'General', 'User Details', 'Cart' are default groups, you can also use something custom
$conditions['Cart']['points'] = __( 'Points', 'woocommerce-advanced-shipping' );
return $conditions;
}
add_filter( 'was_conditions', 'was_conditions_add_points', 10, 1 );
/**
* Add value field for 'date' condition
*
* @param array $values List of value field arguments
* @param string $condition Name of the condition.
* @return array $values List of modified value field arguments.
*/
function was_values_add_points( $values, $condition ) {
switch ( $condition ) {
case 'points':
$values['field'] = 'text';
$values['placeholder'] = '0';
// Option 2; Drop down value field
//
// $values['field'] = 'select';
//
// foreach ( array( '1', '2' ) as $key => $value ) :
// $values['options'][ $key ] = $value;
// endforeach;
break;
}
return $values;
}
add_filter( 'was_values', 'was_values_add_points', 10, 2 );
/**
* Must match given date.
*
* @param bool $match Current matching status. Default false.
* @param string $operator Store owner selected operator.
* @param mixed $value Store owner given value.
* @param array $package Shipping package.
* @return bool If the current user/environment matches this condition.
*/
function was_match_condition_points( $match, $operator, $value, $package ) {
// Check if its a date, when false subtract the number of days
if ( $value > 0 ) :
if ( $operator == '==' ) :
$match = ( $value == $value);
elseif ( $operator == '!=' ) :
$match = ( $value != $value);
elseif ( $operator == '>=' ) :
$match = ( $value >= $value);
elseif ( $operator == '<=' ) :
$match = ( $value <= $value );
endif;
endif;
return $match;
}
add_action( 'was_match_condition_points', 'was_match_condition_points', 10, 4 );
/**
* Add date description.
*
* @param array $description List of existing descriptions.
* @return array List of modified descriptions.
*/
function was_descriptions_points( $descriptions ) {
$descriptions['points'] = __( 'points use', 'woocommerce-advanced-shipping' );
return $descriptions;
}
add_filter( 'was_descriptions', 'was_descriptions_points' );