0
0
Wordpressframework~10 mins

Payment gateway configuration in Wordpress - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to add a new payment gateway class in WooCommerce.

Wordpress
add_filter('woocommerce_payment_gateways', '[1]');
Drag options to blanks, or click blank then click option'
Amy_gateway_class
Badd_my_gateway
Cregister_gateway
Dpayment_gateway_hook
Attempts:
3 left
💡 Hint
Common Mistakes
Using the gateway class name directly instead of the function name.
Forgetting to return the gateways array inside the function.
2fill in blank
medium

Complete the code to define the payment gateway class extending WooCommerce's base class.

Wordpress
class WC_[1] extends WC_Payment_Gateway {
Drag options to blanks, or click blank then click option'
AMyGateway
BPaymentBase
CGatewayBase
DPaymentGateway
Attempts:
3 left
💡 Hint
Common Mistakes
Not extending WC_Payment_Gateway.
Using a generic class name that conflicts with others.
3fill in blank
hard

Fix the error in the constructor to initialize the gateway ID correctly.

Wordpress
public function __construct() {
    $this->id = '[1]';
}
Drag options to blanks, or click blank then click option'
AMyGateway
Bgateway_id
Cpayment_gateway
Dmy_gateway
Attempts:
3 left
💡 Hint
Common Mistakes
Using uppercase or spaces in the ID.
Using a generic or reserved ID.
4fill in blank
hard

Fill both blanks to add your gateway class to WooCommerce and initialize it.

Wordpress
function [1]($gateways) {
    $gateways[] = '[2]';
    return $gateways;
}
Drag options to blanks, or click blank then click option'
Aadd_my_gateway
BWC_MyGateway
Cregister_gateway
DMyGateway
Attempts:
3 left
💡 Hint
Common Mistakes
Using the class name as the function name.
Adding the wrong string to the gateways array.
5fill in blank
hard

Fill all three blanks to hook your gateway registration function and initialize the gateway.

Wordpress
add_filter('woocommerce_payment_gateways', '[1]');

add_action('plugins_loaded', function() {
    [2] = new [3]();
});
Drag options to blanks, or click blank then click option'
Aadd_my_gateway
B$gateway
CWC_MyGateway
Dregister_gateway
Attempts:
3 left
💡 Hint
Common Mistakes
Not hooking the function correctly.
Forgetting to instantiate the gateway class.