in woocommerce you can activate the payment items via toggle. this is build with ajax.
In chrome browser, network tab i can see the payload object which was send to "wp-admin/admin-ajax.php"
{
action: woocommerce_toggle_gateway_enabled
security: 33212389b2
gateway_id: cheque
}
Is it possible in wordpress directly access the action "woocommerce_toggle_gateway_enabled" via php and set the value?
2
Answers
In WordPress if there’s Ajax action "woocommerce_toggle_gateway_enabled" then there should be somewhere:
So I guess you could call
my_action()
but it seems they all should end withecho
anddie
so it would take some adjustments, probably.It’s an action for AJAX requests. It’s not meant to be used directly in php.
You need to extract the update parts from the action function and create your own function.
https://woocommerce.github.io/code-reference/files/woocommerce-includes-class-wc-ajax.html#source-view.3076
you basically need this code section and remove the
wp_send_json_...()
andwp_die()
functions and you need to pass thegateway_id
in your implementation.