Advertisement
fauzanjeg

Add New Menu in Account Page from Woocommerce

Dec 27th, 2021
1,727
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.54 KB | None | 0 0
  1. /** START Add New Menu in Account Page  from Woocommerce */
  2. /* Add Subscription and Unlocked Posts Endpoint for Account Page from Woocommerce */
  3. function subscription_and_unlocked_posts_new_endpoint() {
  4.     add_rewrite_endpoint( 'subscription', EP_ROOT | EP_PAGES );
  5.     add_rewrite_endpoint( 'unlocked-posts', EP_ROOT | EP_PAGES );
  6. }
  7. add_action( 'init', 'subscription_and_unlocked_posts_new_endpoint' );
  8.  
  9. /* Create Subscription Content in Account Page from Woocommerce */
  10. function subscription_endpoint_content() {
  11.     include JNEWS_PAYWALL_DIR . 'template/frontend-status-1.php';
  12. }
  13. add_action( 'woocommerce_account_subscription_endpoint', 'subscription_endpoint_content' );
  14.  
  15. /* Create Unlocked Posts Content in Account Page from Woocommerce */
  16. function unlocked_posts_endpoint_content() {
  17.     include JNEWS_PAYWALL_DIR . 'template/frontend-status-2.php';
  18. }
  19. add_action( 'woocommerce_account_unlocked-posts_endpoint', 'unlocked_posts_endpoint_content' );
  20.  
  21. /* Add Menu Subscription and Unlocked Posts to Account Page from Woocommerce */
  22. function add_subscription_and_unlocked_posts_menu( $menu ) {
  23.     $item = array(
  24.         'subscription'   => esc_html__( 'Subscription', 'jnews-paywall' ),
  25.         'unlocked-posts' => esc_html__( 'Unlocked Posts', 'jnews-paywall' ),
  26.     );
  27.  
  28.     $count = count( $menu );
  29.  
  30.     $menu = array_merge( array_slice( $menu, 0, $count - 1 ), $item, array_slice( $menu, $count - 1 ) );
  31.  
  32.     return $menu;
  33. }
  34. add_filter( 'woocommerce_account_menu_items', 'add_subscription_and_unlocked_posts_menu' );
  35. /** END Add New Menu in Account Page  from Woocommerce */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement