-
-
Save dexit/83e03298a591915a32acb9824ec0a33e to your computer and use it in GitHub Desktop.
WOOCOMMERCE add page in my account
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Ajoute un tab/endpoints dans la partie mon compte | |
* https://nicola.blog/2017/08/01/add-enquiry-form-my-account-woocommerce-contact-form-7/ | |
* | |
*/ | |
class WC_Custom_My_Account_Tabs extends WC_Query { | |
/** | |
* Adds main filters and actions and inits the endpoints. | |
*/ | |
public function __construct() { | |
add_action( 'init', array( $this, 'add_endpoints' ) ); | |
if ( ! is_admin() ) { | |
add_filter( 'query_vars', array( $this, 'add_query_vars' ), 0 ); | |
add_filter( 'woocommerce_account_menu_items', array( $this, 'edit_navigation' ) ); | |
add_action( 'woocommerce_account_contact-us_endpoint', array( $this, 'add_custom_tab_content' ) ); | |
} | |
$this->init_query_vars(); | |
} | |
/** | |
* Inits the query vars for WooCommerce | |
*/ | |
public function init_query_vars() { | |
$this->query_vars = array( | |
'contact-us' => 'contact-us', | |
); | |
} | |
/** | |
* Edits the navigation in the page My Account adding a new Contact Us tab. | |
* | |
* @param array $items The existing tab items. | |
* @return array | |
*/ | |
public function edit_navigation( $items ) { | |
if ( ! isset( $items['contact-us'] ) ) { | |
$last_item = array_splice( $items, -1, 1 ); | |
$contact = array( | |
'contact-us' => esc_html( 'Contact Us' ), | |
); | |
$items = array_merge( $items, $contact, $last_item ); | |
} | |
return $items; | |
} | |
/** | |
* Prints the contact tab content from a template in theme-name/woocommerce/myaccount/ | |
*/ | |
public function add_custom_tab_content() { | |
wc_get_template( 'myaccount/contact.php', array(), '', get_stylesheet() . 'woocommerce/' ); | |
} | |
} | |
new WC_Custom_My_Account_Tabs(); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment