1 <?php
2 3 4 5 6 7 8 9 10 11
12
13 14 15 16 17 18
19 function wc_get_page_id( $page ) {
20
21 if ( $page == 'pay' || $page == 'thanks' ) {
22 _deprecated_argument( __FUNCTION__, '2.1', 'The "pay" and "thanks" pages are no-longer used - an endpoint is added to the checkout instead. To get a valid link use the WC_Order::get_checkout_payment_url() or WC_Order::get_checkout_order_received_url() methods instead.' );
23
24 $page = 'checkout';
25 }
26 if ( $page == 'change_password' || $page == 'edit_address' || $page == 'lost_password' ) {
27 _deprecated_argument( __FUNCTION__, '2.1', 'The "change_password", "edit_address" and "lost_password" pages are no-longer used - an endpoint is added to the my-account instead. To get a valid link use the wc_customer_edit_account_url() function instead.' );
28
29 $page = 'myaccount';
30 }
31
32 $page = apply_filters( 'woocommerce_get_' . $page . '_page_id', get_option('woocommerce_' . $page . '_page_id' ) );
33
34 return $page ? $page : -1;
35 }
36
37 38 39 40 41 42 43 44
45 function wc_get_endpoint_url( $endpoint, $value = '', $permalink = '' ) {
46 if ( ! $permalink )
47 $permalink = get_permalink();
48
49
50 $endpoint = isset( WC()->query->query_vars[ $endpoint ] ) ? WC()->query->query_vars[ $endpoint ] : $endpoint;
51
52 if ( get_option( 'permalink_structure' ) ) {
53 if ( strstr( $permalink, '?' ) ) {
54 $query_string = '?' . parse_url( $permalink, PHP_URL_QUERY );
55 $permalink = current( explode( '?', $permalink ) );
56 } else {
57 $query_string = '';
58 }
59 $url = trailingslashit( $permalink ) . $endpoint . '/' . $value . $query_string;
60 } else {
61 $url = add_query_arg( $endpoint, $value, $permalink );
62 }
63
64 return apply_filters( 'woocommerce_get_endpoint_url', $url );
65 }
66
67 68 69 70 71 72 73
74 function wc_lostpassword_url() {
75 return wc_get_endpoint_url( 'lost-password', '', get_permalink( wc_get_page_id( 'myaccount' ) ) );
76 }
77 add_filter( 'lostpassword_url', 'wc_lostpassword_url', 10, 0 );
78
79
80 81 82 83 84
85 function wc_customer_edit_account_url() {
86 $edit_account_url = wc_get_endpoint_url( 'edit-account', '', get_permalink( wc_get_page_id( 'myaccount' ) ) );
87
88 return apply_filters( 'woocommerce_customer_edit_account_url', $edit_account_url );
89 }
90
91 92 93 94 95 96 97
98 function ( $items, $args ) {
99 if ( ! is_user_logged_in() ) {
100
101 $hide_pages = array();
102 $hide_pages[] = (int) wc_get_page_id( 'logout' );
103 $hide_pages = apply_filters( 'woocommerce_logged_out_hidden_page_ids', $hide_pages );
104
105 foreach ( $items as $key => $item ) {
106 if ( strstr( $item->url, 'customer-logout' ) )
107 unset( $items[ $key ] );
108 }
109 }
110 return $items;
111 }
112 add_filter( 'wp_nav_menu_objects', 'wc_nav_menu_items', 10, 2 );
113
114
115 116 117 118 119 120 121
122 function ( $menu_items, $args ) {
123
124 if ( ! is_woocommerce() ) return $menu_items;
125
126 $shop_page = (int) wc_get_page_id('shop');
127 $page_for_posts = (int) get_option( 'page_for_posts' );
128
129 foreach ( (array) $menu_items as $key => $menu_item ) {
130
131 $classes = (array) $menu_item->classes;
132
133
134 if ( $page_for_posts == $menu_item->object_id ) {
135 $menu_items[$key]->current = false;
136
137 if ( in_array( 'current_page_parent', $classes ) )
138 unset( $classes[ array_search('current_page_parent', $classes) ] );
139
140 if ( in_array( 'current-menu-item', $classes ) )
141 unset( $classes[ array_search('current-menu-item', $classes) ] );
142
143
144 } elseif ( is_shop() && $shop_page == $menu_item->object_id ) {
145 $menu_items[$key]->current = true;
146 $classes[] = 'current-menu-item';
147 $classes[] = 'current_page_item';
148
149
150 } elseif ( is_singular( 'product' ) && $shop_page == $menu_item->object_id ) {
151 $classes[] = 'current_page_parent';
152 }
153
154 $menu_items[$key]->classes = array_unique( $classes );
155
156 }
157
158 return $menu_items;
159 }
160 add_filter( 'wp_nav_menu_objects', 'wc_nav_menu_item_classes', 2, 20 );
161
162
163 164 165 166 167 168 169 170 171
172 function wc_list_pages( $pages ) {
173 global $post;
174
175 if (is_woocommerce()) {
176 $pages = str_replace( 'current_page_parent', '', $pages);
177 $shop_page = 'page-item-' . wc_get_page_id('shop');
178
179 if (is_shop()) :
180 $pages = str_replace($shop_page, $shop_page . ' current_page_item', $pages);
181 else :
182 $pages = str_replace($shop_page, $shop_page . ' current_page_parent', $pages);
183 endif;
184 }
185 return $pages;
186 }
187 add_filter( 'wp_list_pages', 'wc_list_pages' );
188