• Resolved jannis01

    (@jannis01)


    Hi,

    we use the following code snippets to filter payment and shipping methods, which when in functions.php enabled, create a conflict with your plugin. The plugin admin dashboards stay empty and do not load anything. Any suggestion or code correction would be appreciated.

    // /**
    // * ==================================================================================
    // * WooCommerce Disable Payment Gateway for a Specific Country
    // * ==================================================================================
    // */
    function ts_disable_payment_gateway_by_country($available_payment_gateways)
    {
    global $woocommerce;
    if (is_admin()) return $available_payment_gateways;
    if (WC()->customer->get_billing_country() == 'CY') {
    if (isset($available_payment_gateways['bacs'])) {
    unset($available_payment_gateways['bacs']);
    }
    if (isset($available_payment_gateways['cheque'])) {
    unset($available_payment_gateways['cheque']);
    }
    if (isset($available_payment_gateways['cod'])) {
    unset($available_payment_gateways['cod']);
    }
    }
    return $available_payment_gateways;
    }
    add_filter('woocommerce_available_payment_gateways', 'ts_disable_payment_gateway_by_country'); // /**
    // * ==================================================================================
    // * @snippet Disable Other Payment Gateways If Local Pickup Shipping Method Chosen
    // * ==================================================================================
    // */
    function gateway_disable_shipping_326($available_gateways)
    {
    if (!is_admin()) {
    $chosen_methods = WC()->session->get('chosen_shipping_methods');
    $chosen_shipping = $chosen_methods[0];
    if (0 === strpos($chosen_shipping, 'local_pickup')) {
    unset($available_gateways['cod']);
    //unset( $available_gateways['cop'] );
    unset($available_gateways['bacs']);
    }
    }
    return $available_gateways;
    }
    add_filter('woocommerce_available_payment_gateways', 'gateway_disable_shipping_326');
    • This topic was modified 2 years, 9 months ago by jannis01.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter jannis01

    (@jannis01)

    Solved

    I have a similar problem, how did you fix it?

    Thread Starter jannis01

    (@jannis01)

    I’ve changed the code based on other online examples to:

    /**

    • ==================================================================================
    • @snippet Disable Other Payment Gateways If Local Pickup Shipping Method Chosen
    • ==================================================================================
      */
      function gateway_disable_for_shipping_rate( $available_gateways ) {
      if ( ! is_admin() && WC()->session ) {
      $chosen_methods = WC()->session->get( ‘chosen_shipping_methods’ );
      $chosen_shipping = $chosen_methods[0];
      if ( isset( $available_gateways[‘cod’] ) && 0 === strpos( $chosen_shipping, ‘local_pickup’ ) ) {
      unset( $available_gateways[‘cod’] );
      }
      if ( isset( $available_gateways[‘bacs’] ) && 0 === strpos( $chosen_shipping, ‘local_pickup’ ) ) {
      unset( $available_gateways[‘bacs’] );
      }
      }
      return $available_gateways;
      }
      add_filter( ‘woocommerce_available_payment_gateways’, ‘gateway_disable_for_shipping_rate’ );

    and

    /**

    • ==================================================================================
    • WooCommerce Disable Payment Gateway for a Specific Country
    • ==================================================================================
      */
      function ts_disable_payment_gateway_by_country($available_payment_gateways)
      {
      global $woocommerce;
      if (is_admin()) return $available_payment_gateways;
      if (WC()->customer && WC()->customer->get_billing_country() == ‘CY’) {
      if (isset($available_payment_gateways[‘bacs’])) {
      unset($available_payment_gateways[‘bacs’]);
      }
      if (isset($available_payment_gateways[‘cheque’])) {
      unset($available_payment_gateways[‘cheque’]);
      }
      if (isset($available_payment_gateways[‘cod’])) {
      unset($available_payment_gateways[‘cod’]);
      }
      }
      return $available_payment_gateways;
      }
      add_filter(‘woocommerce_available_payment_gateways’, ‘ts_disable_payment_gateway_by_country’);

    Hope that helps you out,

    Cheers

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Plugin admin dashboards empty’ is closed to new replies.