Guest User

Untitled

a guest
Dec 8th, 2016
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.12 KB | None | 0 0
  1.  
  2. //Step one- you need to create a page and grab its page id
  3. //Step two - paste the set of functions in your functions.php file
  4. //Step - In this example Vidoe is the page and it's the end point
  5. // create a custom end point in the My Accunt Page
  6. function custom_wc_end_point() {
  7.     if(class_exists('WooCommerce')){
  8.     add_rewrite_endpoint('videos', EP_ROOT | EP_PAGES );
  9.     add_rewrite_endpoint('new_one', EP_ROOT | EP_PAGES );
  10. }
  11. }
  12. add_action( 'init', 'custom_wc_end_point' );
  13. function custom_endpoint_query_vars( $vars ) {
  14.     $vars[] = 'videos';
  15.      $vars[] = 'new_one';
  16.     return $vars;
  17. }
  18. add_filter( 'query_vars', 'custom_endpoint_query_vars', 0 );
  19. function ac_custom_flush_rewrite_rules() {
  20.     flush_rewrite_rules();
  21. }
  22. add_action( 'after_switch_theme', 'ac_custom_flush_rewrite_rules' );
  23. // add the custom endpoint in the my account nav items
  24. function custom_endpoint_acct_menu_item( $items ) {
  25.    
  26.     $logout = $items['customer-logout'];
  27.     unset( $items['customer-logout'] );
  28.     $items['videos'] = __( 'Videos', 'woocommerce' ); // replace videos with your endpoint name
  29.     $items['new_one'] = __( 'New One', 'woocommerce' ); // replace videos with your endpoint name
  30.     $items['customer-logout'] = $logout;
  31.         return $items;
  32. }
  33. add_filter( 'woocommerce_account_menu_items', 'custom_endpoint_acct_menu_item' );
  34. // fetch content from your source page (in this case video page)
  35. function fetch_content_custom_endpoint() {
  36.     global $post;
  37.     $id = "987452884"; // your video page id
  38.     ob_start();
  39.     $output = apply_filters('the_content', get_post_field('post_content', $id));
  40.     $output .= ob_get_contents();
  41.     ob_end_clean();
  42.     echo $output;
  43. }
  44. add_action( 'woocommerce_account_videos_endpoint', 'fetch_content_custom_endpoint' );
  45.  
  46. function fetch_content_custom_endpoint_two() {
  47.     global $post;
  48.     $id = "987452490"; // your new one page id
  49.     ob_start();
  50.     $output = apply_filters('the_content', get_post_field('post_content', $id));
  51.     $output .= ob_get_contents();
  52.     ob_end_clean();
  53.     echo $output;
  54. }
  55. add_action( 'woocommerce_account_new_one_endpoint', 'fetch_content_custom_endpoint_two' );
Add Comment
Please, Sign In to add comment