Locked Payment Methods for WooCommerce is a relatively simple plugin but it provides a few helpful functions and its functionality can easily be extended using a few key hooks.
Functions
All functions are located in the functions.php and src/functions/* files. You can check their parameters and return values in said locations. The components IDs can be found in the config_prod.php and config-premium_prod.php files.
Function name | Description |
---|---|
dws_wc_lpm_di_container | Returns the dependency injection container instance. |
dws_wc_lpm_instance | Returns the plugin’s main class instance from the DI container. |
dws_wc_lpm_component | Returns a given plugin component from the DI container by its ID. |
dws_wc_lpm_get_raw_setting | Returns the raw database value of a given setting. |
dws_wc_lpm_get_validated_setting | Returns the validated database value of a given setting. |
Function name | Description |
---|---|
dws_wc_lpm_check_payment_method_access_via_user_meta | Returns whether a payment method is locked or not for a given user based on the user meta strategy. |
dws_wc_lpm_check_payment_method_access_via_user_roles | Returns whether a payment method is locked or not for a given user based on the user roles strategy. |
dws_wc_lpm_check_payment_method_access_via_groups | Returns whether a payment method is locked or not for a given user based on the Groups integration strategy. |
dws_wc_lpm_check_payment_method_access_via_wc_memberships | Returns whether a payment method is locked or not for a given user based on the WC Memberships integration strategy. |
dws_wc_lpm_check_payment_method_access_for_user | Returns whether a payment method is locked or not for a given user based on all active strategies. |
dws_wc_lpm_check_payment_method_access_via_wc_order_meta | Returns whether a payment method is locked or not for a given order based on the order meta strategy. |
dws_wc_lpm_check_payment_method_access_for_wc_order | Returns whether a payment method is locked or not for a given order based on all applicable strategies. |
Hooks
All hook tags are computationally generated to ensure uniqueness. It is possible to reverse-engineer the end-result, but it is recommended to just use the same helpers in order to ensure future-compatibility.
There are 2 helper functions to help you generate our hooks:
Function name | Description |
---|---|
dws_wc_lpm_get_hook_tag | Returns a plugin-level hook. |
dws_wc_lpm_get_component_hook_tag | Returns a component-level hook. |
Filter which payment methods are locked
add_action( 'dws_wc_lpm_initialized', function() {
add_filter(
dws_wc_lpm_get_component_hook_tag( 'lock-manager', 'locked_payment_methods' ),
function( array $locked_methods_ids, array $gateways ): array {
return $locked_methods_ids;
},
10,
2
);
} );
Code language: PHP (php)
Filter whether a payment method is locked or not
add_action( 'dws_wc_lpm_initialized', function() {
add_filter(
dws_wc_lpm_get_component_hook_tag( 'lock-manager', 'is_locked_payment_method' ),
function( bool $is_locked, string $locked_method_id ): array {
return $is_locked;
},
10,
2
);
} );
Code language: PHP (php)
add_action( 'dws_wc_lpm_initialized', function() {
$locked_method_id = 'my-dummy-gateway-id';
add_filter(
dws_wc_lpm_get_component_hook_tag( 'lock-manager', 'is_locked_payment_method', array( $locked_method_id ) ),
function( bool $is_locked ): bool {
return $is_locked;
}
);
} );
Code language: PHP (php)