Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
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.
✗ Incorrect
The 'woocommerce_payment_gateways' filter requires a function name that adds your gateway class to the list.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Not extending WC_Payment_Gateway.
Using a generic class name that conflicts with others.
✗ Incorrect
Your custom gateway class should extend WC_Payment_Gateway and have a unique name.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using uppercase or spaces in the ID.
Using a generic or reserved ID.
✗ Incorrect
The gateway ID should be lowercase and unique, usually matching your gateway slug.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the class name as the function name.
Adding the wrong string to the gateways array.
✗ Incorrect
The function name adds the gateway class name string to the gateways array.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Not hooking the function correctly.
Forgetting to instantiate the gateway class.
✗ Incorrect
You hook your function to the filter, then create an instance of your gateway class.