/** * Retrieves the referral rate for an affiliate * * @since 1.0 * @param int $affiliate_id The ID of the affiliate we are getting a rate for * @param bool $formatted Whether to return a formatted rate with %/currency * @param string $product_rate A custom product rate that overrides site/affiliate settings * @return string */ function affwp_get_affiliate_rate($affiliate_id = 0, $formatted = false, $product_rate = '') { // Global referral rate setting, fallback to 20 $default_rate = affiliate_wp()->settings->get('referral_rate', 20); $default_rate = affwp_abs_number_round($default_rate); // Get product-specific referral rate, fallback to global rate $product_rate = affwp_abs_number_round($product_rate); $product_rate = null !== $product_rate ? $product_rate : $default_rate; // Get affiliate-specific referral rate $affiliate_rate = affiliate_wp()->affiliates->get_column('rate', $affiliate_id); // Get rate in order of priority: Affiliate -> Product -> Global $rate = affwp_abs_number_round($affiliate_rate); $rate = null !== $rate ? $rate : $product_rate; // Get the referral rate type $type = affwp_get_affiliate_rate_type($affiliate_id); // Format percentage rates $rate = 'percentage' === $type ? $rate / 100 : $rate; /** * Filter the affiliate rate * * @param string $rate * @param int $affiliate_id * @param string $type */ $rate = (string) apply_filters('affwp_get_affiliate_rate', $rate, $affiliate_id, $type); // Return rate now if formatting is not required if (!$formatted) { return $rate; } // Format the rate based on the type switch ($type) { case 'percentage': $rate = affwp_abs_number_round($rate * 100) . '%'; break; case 'flat': $rate = affwp_currency_filter($rate); break; } return $rate; }
<?php $default_rate = affiliate_wp()->settings->get('referral_rate', 20); $default_rate = affwp_abs_number_round($default_rate); ?> <div class="wrap"> <h2><?php _e('New Affiliate', 'affiliate-wp'); ?> </h2> <form method="post" id="affwp_add_affiliate"> <?php do_action('affwp_new_affiliate_top'); ?> <p><?php printf(__('Use this screen to register a new affiliate. Each affiliate is tied directly to a user account, so if the user account for the affiliate does not yet exist, <a href="%s" target="_blank">create one</a>.', 'affiliate-wp'), admin_url('user-new.php')); ?> </p> <table class="form-table"> <tr class="form-row form-required"> <th scope="row"> <label for="user_name"><?php _e('User', 'affiliate-wp'); ?>
/** * Number Callback * * Renders number fields. * * @since 1.9 * @param array $args Arguments passed by the setting * @global $this->options Array of all the AffiliateWP Options * @return void */ function number_callback($args) { // Get value, with special consideration for 0 values, and never allowing negative values $value = isset($this->options[$args['id']]) ? $this->options[$args['id']] : null; $value = !is_null($value) && '' !== $value && floatval($value) >= 0 ? floatval($value) : null; // Saving the field empty will revert to std value, if it exists $std = isset($args['std']) && !is_null($args['std']) && '' !== $args['std'] && floatval($args['std']) >= 0 ? $args['std'] : null; $value = !is_null($value) ? $value : (!is_null($std) ? $std : null); $value = affwp_abs_number_round($value); // Other attributes and their defaults $max = isset($args['max']) ? $args['max'] : 999999; $min = isset($args['min']) ? $args['min'] : 0; $step = isset($args['step']) ? $args['step'] : 1; $size = isset($args['size']) && !is_null($args['size']) ? $args['size'] : 'regular'; $html = '<input type="number" step="' . esc_attr($step) . '" max="' . esc_attr($max) . '" min="' . esc_attr($min) . '" class="' . $size . '-text" id="affwp_settings[' . $args['id'] . ']" name="affwp_settings[' . $args['id'] . ']" placeholder="' . esc_attr($std) . '" value="' . esc_attr(stripslashes($value)) . '"/>'; $html .= '<p class="description"> ' . $args['desc'] . '</p>'; echo $html; }