• Resolved Mo

    (@nadhonar)


    Hi there, Is it possible to hide a Woocommerce gateway based on the presence of specific string? For example if the content of the order contains this sentence: “I don’t need invoice”, then our gateway won’t be displayed.

    Regards

    • This topic was modified 3 months, 3 weeks ago by Mo.
Viewing 9 replies - 1 through 9 (of 9 total)
  • Hi,

    Thankyou for reaching out to us.

    Unfortunately, the plugin does not support that specific feature. You can manage the visibility of the payment gateway based on the following criteria:

    • Require Date/Time
    • Exclude Date/Time
    • Require Customer IP
    • Exclude Customer IP
    • Require User
    • Exclude User
    • Minimum Cart Total
    • Maximum Cart Total
    • Require Currency
    • Exclude Currency
    • Require Language
    • Exclude Language

    Thank you for your understanding. If you have any further questions or need assistance, please don’t hesitate to reach out.

    Best regards,

    Thread Starter Mo

    (@nadhonar)

    Thanks for the reply, But We can hide the gateways by the following codes:

    //  Disable Woocommerce payment methods based on product title containing 'SPECIFIC STRING'
    add_filter( 'woocommerce_available_payment_gateways', 'wpsh_disable_gateways_based_on_product_title', 10, 1 );

    function wpsh_disable_gateways_based_on_product_title( $gateways ) {

    // Check if cart is initialized
    if ( ! WC()->cart ) {
    return $gateways;
    }

    // Loop through cart items
    foreach ( WC()->cart->get_cart() as $cart_item ) {
    $product = $cart_item['data'];
    $product_title = $product->get_name();

    // Check if the product title contains 'SPECIFIC STRING'
    if ( stripos( $product_title, 'SPECIFIC STRING' ) !== false ) {
    // If the condition is met, disable the payment gateway
    if ( isset( $gateways['bacs'] ) ) {
    unset( $gateways['bacs'] );
    }
    break;
    }
    }

    return $gateways;
    }

    Also:

    // Disable Woocommerce payment methods based on product description containing 'SPECIFIC STRING'
    add_filter( 'woocommerce_available_payment_gateways', 'wpsh_disable_gateways_based_on_product_description', 10, 1 );

    function wpsh_disable_gateways_based_on_product_description( $gateways ) {

    // Check if cart is initialized
    if ( ! WC()->cart ) {
    return $gateways;
    }

    // Loop through cart items
    foreach ( WC()->cart->get_cart() as $cart_item ) {
    $product = $cart_item['data'];
    $product_description = $product->get_description();

    // Check if the product description contains 'SPECIFIC STRING'
    if ( stripos( $product_description, 'SPECIFIC STRING' ) !== false ) {
    // If the condition is met, disable the payment gateway
    if ( isset( $gateways['bacs'] ) ) {
    unset( $gateways['bacs'] );
    }
    break;
    }
    }

    return $gateways;
    }

    Regards

    Hi,

    I will forward your ticket to the advanced development team for their advice on this custom code.

    Thank you for your reply.

    Best regards,

    Plugin Author Algoritmika

    (@algoritmika)

    Hi, @nadhonar,

    Thank you for the idea.

    Please update the plugin to the latest v2.3.0 (released today).

    After the update, you will find a new “Product Title” section (in “WooCommerce > Settings > Conditional Payment Gateways”).

    Please give it a try and let me know what you think.

    And if you like the plugin, please consider leaving me a rating.

    Thread Starter Mo

    (@nadhonar)

    Thanks a lot

    Thread Starter Mo

    (@nadhonar)

    I’ve checked the added features; You Rock!

    Plugin Author Algoritmika

    (@algoritmika)

    Hi, @nadhonar,

    Happy to help ??

    Thread Starter Mo

    (@nadhonar)

    Thank you, I should set this rules for my own payment gateway. So Pro version is required. Right?

    Plugin Author Algoritmika

    (@algoritmika)

    Hi, @nadhonar,

    Yes, that’s correct – to set the rules for a custom payment gateway, you’ll need our Pro version.

Viewing 9 replies - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.