Viewing 11 replies - 16 through 26 (of 26 total)
  • Hey Sean Donovan,

    How much will you charge to make this into a plugin. Say we want a box on the products page, where you can select the payment methods available for that product?

    This worked like a charm! Sean, I’d be interested in buying this plugin or paying to have you develop it.

    Here’s what I did to remove mijireh and checks, but leave paypal for a specific product:

    add_filter(‘woocommerce_available_payment_gateways’,’filter_gateways’,1);

    function filter_gateways($gateways){
    global $woocommerce;
    foreach ($woocommerce->cart->cart_contents as $key => $values ) {
    //store product id’s in array
    $highpriceditems = array(24);

    if(in_array($values[‘product_id’],$highpriceditems)){

    unset($gateways[‘mijireh_checkout’]);
    unset($gateways[‘cheque’]);
    break;
    }}
    return $gateways;
    }

    Anyone have something similar to restrict shipping methods based on a particular product ID/IDs? Essentially I have a few products that require special handling (HAZMAT) and can only be shipped UPS Ground. I’d like to eliminate other shipping options like USPS and UPS non-ground choices. I think adding a filter like above would work but while I’m ok with CSS I’m way over my head with something like this.

    Any help would be much appreciated!!

    Does anyone have advice on how to do a combo – restrict some gateways for some products and others for others? I can’t seem to get the proper function down. Here’s what I have, and what I want to add below.

    add_filter(‘woocommerce_available_payment_gateways’,’filter_gateways’,1);

    function filter_gateways($gateways){
    global $woocommerce;
    foreach ($woocommerce->cart->cart_contents as $key => $values ) {
    //store product id’s in array
    $highpriceditems = array(24,55);

    if(in_array($values[‘product_id’],$highpriceditems)){

    unset($gateways[‘mijireh_checkout’]);
    unset($gateways[‘cheque’]);
    unset($gateways[‘bitpay’]);
    unset($gateways[‘wepay’]);
    break;
    }}
    return $gateways;
    }

    *****

    For products 24 and 55, those 4 gateways do NOT show up at checkout. this is good.

    But, I can’t figure out how to do something different for product 75. I want to do the following:

    unset($gateways[‘mijireh_checkout’]);
    unset($gateways[‘paypal’]);

    FYI – I’m not worried about all those products in the cart at the same time, because the first 2 are subscription products, they can’t be in there together anyway.

    Excellent solution.
    And would it be possible to set the filter for a certain shipping class?

    Is there a way to apply his filter for the order subtotal?

    For example, if the cart subtotal is less that 50, the “COD” option shall be hidden.

    Do you have any idea on how to achieve that?

    Hello,
    Thank you for the snippet, it’s really helpful.
    I’m trying to achieve the same results, but with the following : if and only if there is only 1 category type in the cart, I want to disable on payment.
    I tried :

    function filter_gateways($gateways){
    
    $payment_NAME = 'cheque'; // <--------------- change this
    $category_ID1 = '13';  // <----------- and this
    $category_ID2 = '14';  // <----------- and this
    $category_ID3 = '15';  // <----------- and this
    
     global $woocommerce;
    
     foreach ($woocommerce->cart->cart_contents as $key => $values ) {
    	// Get the terms, i.e. category list using the ID of the product
    	$terms = get_the_terms( $values['product_id'], 'product_cat' );
    	// Because a product can have multiple categories, we need to iterate through the list of the products category for a match
    	foreach ($terms as $term) {
    		// 20 is the ID of the category for which we want to remove the payment gateway
    		if(($term->term_id != $category_ID1) AND ($term->term_id != $category_ID2)  AND ($term->term_id != $category_ID3) ){
                   unset($gateways[$payment_NAME]);
                       // If you want to remove another payment gateway, add it here i.e. unset($gateways['cod']);
    					break;
              }
    	    break;
    	}
    
       }
    	return $gateways;
    
    }
    
    add_filter('woocommerce_available_payment_gateways','filter_gateways');

    Because I thought that checking if products are not in all category except the one I’m trying to isolate, I would be able to de activate the check method, but it’s not working.
    What do you think ?
    Thank you,
    Manue

    Is there also a way to make the choice of payment gateways based on shipping method?
    for example, if someone want the shipping “local pickup” i want to exclude gateway “credit card” and visa versa.

    Hope someone can help me with a usefull code snippet

    Anyone?
    i just need a usefull push in the right direction.

    Friends

    I wish I could tell which form of payment a particular product will have.

    Example: Product X will have enabled transfer and card “Cielo”
    Product Y card only (Cielo “
    Product W only “Cielo” and “PagSeguro”
    Product Z All forms of payment authorized

    Could anyone help me?

    Great thread.
    I’d like to accomplish the same based on ‘Order Total.’
    i.e. If Order Total is greater than $100, only allow this/these payment options.
    Thanks for your guidance!

    @clickconversion: If you require assistance then, as per the Forum Welcome, please post your own topic.

Viewing 11 replies - 16 through 26 (of 26 total)
  • The topic ‘Restrict payment options based on product’ is closed to new replies.