Just need some advice/help on implementing this scenario.

Hey guys,
Just need some advice/help on implementing this scenario.
I'm currently developing a custom wordpress theme along with pro site for a client but what i want do, is to remove some/all of woocommerce default payments for users based on their pro site level. i currently have 4 levels.
1.ad hoc
2.bona fide
3.carpe
4.infinitum

so, here it is.

i have a custom function `add_filter( 'woocommerce_payment_gateways', 'growdev_remove_unused_payment_gateways', 20, 1 );
/**
* This function will remove all of the WooCommerce standard gateways from the
* WooCommerce > Settings > Checkout dashboard.
*/
function growdev_remove_unused_payment_gateways( $load_gateways ) {

$remove_gateways = array(
'WC_Gateway_BACS',
'WC_Gateway_Cheque',
'WC_Gateway_COD',
'WC_Gateway_Paypal',
'WC_Gateway_Simplify_Commerce',
'WC_Addons_Gateway_Simplify_Commerce'
);

foreach ( $load_gateways as $key => $value ) {

if ( in_array( $value, $remove_gateways ) ) {
unset( $load_gateways[ $key ] );
}
}

return $load_gateways;
}

but i wish this function to be executed base on the user pro site level, because users with user level 3 or lower can't not see the woocommerce default gateway etc..

Thanks for your advice/help.

  • Tom Whittaker

    okay. i want use pro site to check the current SITE pro site level, ex: if its 1,2,3,or 4.
    then for example if its 1 then i want to execute this function

    function odin_wc_remote_gateway( $methods ) {
    // Search mijireh ID.
    $mijireh = array_search( 'WC_Gateway_Mijireh', $methods );

    // Remove mijireh
    unset( $methods[ $mijireh ] );

    return $methods;
    }

    add_filter( 'woocommerce_payment_gateways', 'odin_wc_remote_gateway' );

    with this function it removes the Direct Bank Transfer from woocommerce setting page.
    so in this case it remove it from all users, but i want it to remove it based on certain pro site user level.

  • Tom Whittaker

    I get it to work, but i don't know if there's a better way to do it. here's my code.

    function odin_wc_remote_gateway( $methods ) {
    global $wpdb,$level;
    $blog_id = $wpdb->blogid;
    $sql = "SELECT level FROM {$wpdb->base_prefix}pro_sites WHERE blog_ID = '$blog_id'";
    $level = $wpdb->get_var($sql);
    // Search mijireh ID.
    $mijireh = array_search( 'WC_Gateway_Mijireh', $methods );
    // Remove mijireh based user level
    if ($level ==2){
    unset( $methods[ $mijireh ] );
    }

    return $methods;
    }

    add_filter( 'woocommerce_payment_gateways', 'odin_wc_remote_gateway' );

  • Tom Whittaker

    here's the full code in case someone trying to accomplish something like this

    function odin_wc_remote_gateway( $methods ) {
    global $wpdb,$level,$blog_id;

    if(is_pro_site($blog_id, $level )){
    $blog_id = $wpdb->blogid;
    $sql = "SELECT level FROM {$wpdb->base_prefix}pro_sites WHERE blog_ID = '$blog_id'";
    $level = $wpdb->get_var($sql);
    // Search mijireh ID.
    $DirectBankTransfer = array_search( 'WC_Gateway_BACS', $methods );
    $paypal = array_search( 'WC_Gateway_Paypal', $methods );
    $cheque = array_search( 'WC_Gateway_Cheque', $methods );
    $cashOnDelivery = array_search( 'WC_Gateway_COD', $methods );
    $simplify = array_search( 'WC_Gateway_Simplify_Commerce', $methods );
    $simplify_addons = array_search( 'WC_Addons_Gateway_Simplify_Commerce', $methods );
    // Remove gateways based user level
    if ($level ==1){
    /*
    unset neccessary variables in methods []
    */
    //unset( $methods[ $ ] );
    unset( $methods[ $paypal ] );
    }
    }

    return $methods;
    }

    add_filter( 'woocommerce_payment_gateways', 'odin_wc_remote_gateway' );

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.