Advanced Dynamic Pricing For WooCommerce

Groups (use group/role discounts), by itthinx

Compatibility guide for Groups (use group/role discounts) by itthinx and Advanced Dynamic Pricing: adjust settings and add helper code so group- or role-based discounts are applied correctly.

Add provided code to functions.php and update Settings.

Calculation option “Use prices modified by other plugins” must be ON.

System option “Suppress other pricing plugins in frontend” must be OFF.

add_filter( 'wdp_preloaded_list_user_roles', function ( $list ) {
	$groups = array();
	if ( function_exists( '_groups_get_tablename' ) ) {
		global $wpdb;
		$groups_table = _groups_get_tablename( 'group' );
		$groups = $wpdb->get_results( "SELECT * FROM $groups_table ORDER BY name" );
	}

	$groups = is_array( $groups ) ? $groups : array();

	foreach ( $groups as $group ) {
		$list[] = array(
			'id'   => '(group)' . strtolower( $group->name ),
			'text' => '(group) ' . $group->name,
		);
	}

	return $list;
} );

add_filter( 'wdp_current_user_roles', function ( $roles ) {
	$groups = array();
	$current_user_id = get_current_user_id();

	if ( function_exists( '_groups_get_tablename' ) && $current_user_id ) {
		global $wpdb;
		$groups_table = _groups_get_tablename( 'group' );
		$user_group_table = _groups_get_tablename( 'user_group' );
		$groups       = $wpdb->get_results( "SELECT * FROM {$groups_table} WHERE {$groups_table}.group_id IN (SELECT group_id FROM {$user_group_table} WHERE {$user_group_table}.user_id = {$current_user_id} ) ORDER BY name" );
	}

	$groups = is_array( $groups ) ? $groups : array();

	foreach ( $groups as $group ) {
		$roles[] = '(group)' . strtolower( $group->name );
	}

	return $roles;
} );

 

Have questions? Please submit a support request. We're always happy to help!

Advanced Dynamic Pricing
for WooCommerce
PRO

From $60
Buy
✓ 30-day money-back guarantee