| |
| <?php
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| if ( ! defined( 'ABSPATH' ) ) {
|
| exit;
|
| }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| add_action( 'wp', function() {
|
|
|
| if ( affwp_cr_role_current_user_has_role( 'influencer_sales' ) ) {
|
| return;
|
| }
|
|
|
| affwp_cr_role_remove_class_hook(
|
| 'woocommerce_after_order_notes',
|
| 'AffiliateWP_Checkout_Referrals_WooCommerce',
|
| 'affiliate_select_or_input'
|
| );
|
|
|
| affwp_cr_role_remove_class_hook(
|
| 'woocommerce_checkout_process',
|
| 'AffiliateWP_Checkout_Referrals_WooCommerce',
|
| 'check_affiliate_field'
|
| );
|
| } );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| add_action( 'woocommerce_init', function() {
|
|
|
| if ( affwp_cr_role_current_user_has_role( 'influencer_sales' ) ) {
|
| return;
|
| }
|
|
|
| affwp_cr_role_remove_class_hook(
|
| 'woocommerce_init',
|
| 'AffiliateWP_Checkout_Referrals_WooCommerce',
|
| 'register_affiliate_select_or_input_for_checkout_block'
|
| );
|
| }, 1 );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| add_filter( 'affwp_checkout_referrals_get_affiliates_args', function( $args, $context ) {
|
|
|
| $influencer_user_ids = get_users( array(
|
| 'role' => 'influencer',
|
| 'fields' => 'ID',
|
| ) );
|
|
|
| if ( empty( $influencer_user_ids ) ) {
|
| $args['user_id'] = array( 0 );
|
| return $args;
|
| }
|
|
|
| $args['user_id'] = array_map( 'absint', $influencer_user_ids );
|
|
|
| return $args;
|
| }, 10, 2 );
|
|
|
|
|
|
|
|
|
| function affwp_cr_role_current_user_has_role( $role ) {
|
|
|
| if ( ! is_user_logged_in() ) {
|
| return false;
|
| }
|
|
|
| $user = wp_get_current_user();
|
|
|
| return in_array( $role, (array) $user->roles, true );
|
| }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| function affwp_cr_role_remove_class_hook( $hook, $class_name, $method ) {
|
|
|
| global $wp_filter;
|
|
|
| if ( ! isset( $wp_filter[ $hook ] ) ) {
|
| return false;
|
| }
|
|
|
| foreach ( $wp_filter[ $hook ]->callbacks as $priority => $callbacks ) {
|
| foreach ( $callbacks as $callback_id => $callback ) {
|
|
|
| if ( ! is_array( $callback['function'] ) ) {
|
| continue;
|
| }
|
|
|
| if ( ! is_object( $callback['function'][0] ) ) {
|
| continue;
|
| }
|
|
|
| if ( get_class( $callback['function'][0] ) !== $class_name ) {
|
| continue;
|
| }
|
|
|
| if ( $callback['function'][1] !== $method ) {
|
| continue;
|
| }
|
|
|
| remove_action( $hook, $callback['function'], $priority );
|
|
|
| return true;
|
| }
|
| }
|
|
|
| return false;
|
| }
|
| |
| |
Comments