skip to Main Content

I want to add a specific rule if the order uses a specific gateway for a plugin.
They have a public function for orders, is it possible I add some code to the function if the order used mycred gateway as well?

Here is the public function.

        /*
         * @param int
         * @return none
         */
        if ($order_id){
            if (is_object($order_id)){
                $order_id = (isset($order_id->ID)) ? $order_id->ID : 0;
            }
            $this->referral_refuse($order_id, $this->source_type);
        }
    }```

2

Answers


  1. Chosen as BEST ANSWER
    public function make_referral_refuse($order_id=0){
        /*
        * @param int
        * @return none
        */
        if ( "Mycred" == $order->get_payment_method_title() ) {
            $this->referral_refuse($order_id, $this->source_type);
            }
        if ($order_id){
            if (is_object($order_id)){
                $order_id = (isset($order_id->ID)) ? $order_id->ID : 0;
            }
            $this->referral_refuse($order_id, $this->source_type);
        }
    }
    

    I can not format the code with comment, So I posted here.

    Btw, I found a filter of the plugin, I am not sure which is the better way,

    Those are the filters, I am not sure which one should I use, but I tried both of the 2 filters, when checkout it shows internal error, I think the code may have some error.

    uap_filter_referral_amount
    uap_public_filter_on_referral_insert_amount_value
    

    The flowing code is what I have tried and shows internal error when checkout:

    function exclude_mycred_gateway( $order ){
        $payment_title = $order->get_payment_method_title();
        if ( $payment_title ) {
            $payment_title == "myCRED";
            return "0";
        }
    }
    
    add_filter( 'uap_filter_referral_amount', 'exclude_mycred_gateway');
    

  2. Based on this tutorial you can calculate the order payment method via:

    $order->get_payment_method_title();
    

    Therefore, you could check if "Mycred" (or whatever title you gave it) equals that calculation and only then proceed with the function:

    if ( "Mycred" == $order->get_payment_method_title() ) {
       $this->referral_refuse($order_id, $this->source_type);
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search