Is it possible to add a capability after someone purchases a product in my child's function file? Tried this but did not worked
add_action( 'cap_added', 'change_user_cap_with_purchase', 1 );
function change_user_cap_with_purchase ( $order_id ){
$order = wc_get_order( $order_id );
foreach( $order->get_items() as $item ) {
// Product ID
if ( $item['product_id'] == 999 ) {
function add_cap_to_role() {
$customer = get_role('customer');
$customer->add_cap('cst11');
}
}
}