Filter uncanny-learndash-groups

learndash_woocommerce_manual_payment_methods

Filters available manual payment methods for LearnDash WooCommerce integration.

add_filter( 'learndash_woocommerce_manual_payment_methods', $callback, 10, 1 );

Description

Filters the array of manual payment methods available for LearnDash WooCommerce integration. Developers can use this to add or remove custom manual payment gateways, influencing which options appear when a user selects a manual payment method for a LearnDash course purchase.


Usage

add_filter( 'learndash_woocommerce_manual_payment_methods', 'your_function_name', 10, 1 );

Return Value

The filtered value.


Examples

/**
 * Filters the list of manual payment methods to exclude 'paypal' if it's present.
 *
 * @param array $manual_payment_methods An array of manual payment method slugs.
 * @return array The modified array of manual payment methods.
 */
add_filter( 'learndash_woocommerce_manual_payment_methods', function( $manual_payment_methods ) {
    // Find the key for 'paypal' if it exists in the array.
    $paypal_key = array_search( 'paypal', $manual_payment_methods, true );

    // If 'paypal' is found, remove it from the array.
    if ( false !== $paypal_key ) {
        unset( $manual_payment_methods[ $paypal_key ] );
    }

    // Return the modified array.
    return $manual_payment_methods;
}, 10, 1 );

Placement

This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.


Source Code

src/classes/woocommerce/woocommerce-payment-complete.php:76

public function autocomplete_uo_groups_order( $status, $order_id ) {
		if ( null === $order_id ) {
			return $status;
		}

		// Order is not in processing status, bail
		if ( 'processing' !== (string) $status ) {
			return $status;
		}

		$order = wc_get_order( $order_id );
		if ( ! $order instanceof WC_Order ) {
			return $status;
		}

		$line_items = $order->get_items();
		// No products found, bail
		if ( ! $line_items ) {
			return $status;
		}

		$course_type       = $this->has_course_type_product( $order );
		$license_type      = $this->has_license_type_product( $order );
		$group_type        = $this->has_groups_type_product( $order );
		$subscription_type = $this->has_subscription_license_type_product( $order );

		/**
		 * Bail early if none of Groups type product found in order
		 */
		if ( false === $course_type && false === $license_type && false === $group_type && false === $subscription_type ) {
			return $status;
		}

		/**
		 * Bail early if using non-payment methods of groups type product
		 */
		if ( $this->has_groups_type_product( $order ) ) {
			$manual_payment_methods = apply_filters(
				'learndash_woocommerce_manual_payment_methods',
				array(
					'bacs',
					'cheque',
					'cod',
				)
			);

			// If using manual payment, bail
			$payment_method = $order->get_payment_method();
			if ( in_array( $payment_method, $manual_payment_methods ) ) {
				return $status;
			}
		}

		$other_products = array();
		foreach ( $line_items as $item ) {
			$product = $item->get_product();
			// Validate product before accessing its methods
			if ( ! ( $product instanceof WC_Product ) ) {
				continue;
			}
			$product_id = $product->get_id();
			// check if product is virtual or downloadable regardless of the product type
			if ( ! $product->get_virtual() && ! $product->get_downloadable() ) {
				// only add to $other_products if it's not a groups type product
				if ( true === $this->is_courses_type_product( $product ) || true === $this->is_license_type_product( $product ) || true === $this->is_groups_type_product( $product ) || true === $this->is_subscription_type_product( $product ) ) {
					continue;
				}
				// The product is not virtual and not groups type
				$other_products[ $product_id ] = $product->get_type();
			}
		}

		// Other product type found which is not virtual type in order, bail
		if ( ! empty( $other_products ) ) {
			return $status;
		}

		// Seems good to mark order complete.
		return 'completed';
	}

Scroll to Top