I need to create category restriction automatically. I have the correct action hook, so please let me know how to insert category restriction automatically.
I haven’t tried this yet, have you searched the s2Member files/codex?
I think you’d edit the global that has the category IDs protected at the level you’re requiring: [hilite code]$GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level" . $n . "_catgs"][/hilite] (where [hilite mono]$n[/hilite] is the level number).
Not sure what stores that in the database, though. You could browse your db to find the categories you protected, to see where they are and then figure out how to edit it with your hack. Unless you want to do it dynamically, then you can do it from a must-use plugin, I guess.
Also, instead of binding it to a specific level, I want to sell it once like specific page/post, but unfortunately, I have not found that configuration in button generation page.
You’d need your customization to get all the post/page IDs from that category and protect it with the Specific Post/Page Restriction. This may help with the access link generation: http://www.s2member.com/codex/stable/s2member/sp_access/c_ws_plugin__s2member_sp_access/#src_doc_sp_access_link_gen%28%29
I hope that helps.