unlimint payment for woocommerce code example

Example 1: woocommerce remove payment method when totla is 0

function payment_gateway_disable_total_amount( $available_gateways ) {
global $woocommerce;
if ( isset( $available_gateways['paypal'] ) && $woocommerce->cart->total == 0 ) {
    unset(  $available_gateways['paypal'] );
}
    return $available_gateways;
}
add_filter( 'woocommerce_available_payment_gateways', 'payment_gateway_disable_total_amount' );

Example 2: woocommerce gateway process payment

public function process_payment( $order_id ) {
    
    $order = wc_get_order( $order_id );
            
    // Mark as on-hold (we're awaiting the payment)
    $order->update_status( 'on-hold', __( 'Awaiting offline payment', 'wc-gateway-offline' ) );
            
    // Reduce stock levels
    $order->reduce_order_stock();
            
    // Remove cart
    WC()->cart->empty_cart();
            
    // Return thankyou redirect
    return array(
        'result'    => 'success',
        'redirect'  => $this->get_return_url( $order )
    );
}

Tags:

Php Example