Hooks and functions reference

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 nameDescription
dws_wc_lpm_di_containerReturns the dependency injection container instance.
dws_wc_lpm_instanceReturns the plugin’s main class instance from the DI container.
dws_wc_lpm_componentReturns a given plugin component from the DI container by its ID.
dws_wc_lpm_get_raw_settingReturns the raw database value of a given setting.
dws_wc_lpm_get_validated_settingReturns the validated database value of a given setting.
Function nameDescription
dws_wc_lpm_check_payment_method_access_via_user_metaReturns 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_rolesReturns 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_groupsReturns 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_membershipsReturns 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_userReturns 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_metaReturns 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_orderReturns 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 nameDescription
dws_wc_lpm_get_hook_tagReturns a plugin-level hook.
dws_wc_lpm_get_component_hook_tagReturns a component-level hook.

It’s recommended to use the action dws_wc_lpm_initialized to register your hooks. It’s guaranteed that the functions above will be present and work on this action.

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)
Updated on September 29, 2021

Was this article helpful?

Related Articles

Need Support?
Can’t find the answer you’re looking for? Don’t worry we’re here to help!
CONTACT SUPPORT