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 5.2.0-beta.1 10.0.2 5.2.0-rc.1 10.0.3 5.2.0-rc.2 10.0.4 5.2.1 10.0.5 5.2.2 10.0.6 5.2.3 10.1.0 5.2.4 10.1.0-rc.1 5.2.5 10.1.0-rc.2 5.3.0 10.1.0-rc.3 5.3.0-beta.1 10.1.0-rc.4 5.3.0-rc.1 10.1.1 5.3.0-rc.2 10.1.2 5.3.1 10.1.3 5.3.2 10.1.4 5.3.3 10.2.0 5.4.0 10.2.0-beta.1 5.4.0-beta.1 10.2.0-beta.2 5.4.0-rc.1 10.2.0-rc.1 5.4.1 10.2.1 5.4.2 10.2.2 5.4.3 10.2.3 5.4.4 10.2.4 5.4.5 10.3.0 5.5.0 10.3.0-beta.1 5.5.0-beta.1 10.3.0-beta.2 5.5.0-rc.1 10.3.0-rc.1 5.5.0-rc.2 10.3.0-rc.2 5.5.1 10.3.1 5.5.2 10.3.2 5.5.3 10.3.3 5.5.4 10.3.4 5.5.5 10.3.5 5.6.0 10.3.6 5.6.0-beta.1 10.3.7 5.6.0-rc.1 10.3.8 5.6.0-rc.2 10.4.0 5.6.1 10.4.0-beta.1 5.6.2 10.4.0-beta.2 5.6.3 10.4.0-rc.1 5.7.0 10.4.1 5.7.0-beta.1 10.4.2 5.7.0-rc.1 10.4.3 5.7.1 10.4.4 5.7.2 10.5.0 5.7.3 10.5.0-beta.1 5.8.0 10.5.0-beta.2 5.8.0-beta.1 10.5.0-rc.1 5.8.0-beta.2 10.5.0-rc.2 5.8.0-rc.1 10.5.0-rc.3 5.8.1 10.5.1 5.8.2 10.5.2 5.9.0 10.5.3 5.9.0-beta.1 10.6.0 5.9.0-rc.1 10.6.0-beta.1 5.9.0-rc.2 10.6.0-beta.2 5.9.1 10.6.0-rc.1 5.9.2 10.6.1 6.0.0 10.6.2 6.0.0-beta.1 10.7.0 6.0.0-rc.1 10.7.0-beta.1 6.0.1 10.7.0-beta.2 6.0.2 10.7.0-rc.1 6.1.0 3.0.0 6.1.0-beta.1 3.0.1 6.1.0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7.1.0-rc.1 3.7.1 7.1.0-rc.2 3.7.2 7.1.1
woocommerce / includes / wc-page-functions.php
woocommerce / includes Last commit date
abstracts 4 days ago admin 4 days ago blocks 1 month ago cli 2 weeks ago customizer 6 months ago data-stores 4 days ago emails 2 weeks ago export 2 weeks ago gateways 2 weeks ago import 1 week ago integrations 1 month ago interfaces 6 months ago legacy 1 month ago libraries 2 weeks ago log-handlers 1 year ago payment-tokens 6 years ago product-usage 1 year ago queue 6 months ago react-admin 1 week ago rest-api 2 days ago shipping 5 months ago shortcodes 2 weeks ago theme-support 2 years ago tracks 2 weeks ago traits 5 years ago walkers 5 years ago wccom-site 2 months ago widgets 1 month ago class-wc-ajax.php 2 days ago class-wc-auth.php 2 years ago class-wc-autoloader.php 10 months ago class-wc-background-emailer.php 3 months ago class-wc-background-updater.php 6 years ago class-wc-brands-brand-settings-manager.php 1 year ago class-wc-brands-coupons.php 1 year ago class-wc-brands.php 2 weeks ago class-wc-breadcrumb.php 6 months ago class-wc-cache-helper.php 2 months ago class-wc-cart-fees.php 2 years ago class-wc-cart-session.php 2 weeks ago class-wc-cart-totals.php 1 year ago class-wc-cart.php 1 month ago class-wc-checkout.php 1 month ago class-wc-cli.php 2 weeks ago class-wc-comments.php 1 week ago class-wc-countries.php 3 months ago class-wc-coupon.php 2 weeks ago class-wc-customer-download-log.php 6 years ago class-wc-customer-download.php 2 years ago class-wc-customer.php 1 month ago class-wc-data-exception.php 8 years ago class-wc-data-store.php 3 years ago class-wc-datetime.php 4 years ago class-wc-deprecated-action-hooks.php 2 years ago class-wc-deprecated-filter-hooks.php 5 months ago class-wc-discounts.php 2 weeks ago class-wc-download-handler.php 2 weeks ago class-wc-emails.php 1 month ago class-wc-embed.php 3 weeks ago class-wc-form-handler.php 2 weeks ago class-wc-frontend-scripts.php 1 month ago class-wc-geo-ip.php 10 months ago class-wc-geolite-integration.php 6 years ago class-wc-geolocation.php 2 weeks ago class-wc-https.php 3 years ago class-wc-install.php 1 week ago class-wc-integrations.php 6 years ago class-wc-log-levels.php 2 years ago class-wc-logger.php 6 months ago class-wc-meta-data.php 2 months ago class-wc-order-factory.php 3 months ago class-wc-order-item-coupon.php 4 years ago class-wc-order-item-fee.php 2 weeks ago class-wc-order-item-meta.php 4 years ago class-wc-order-item-product.php 2 weeks ago class-wc-order-item-shipping.php 7 months ago class-wc-order-item-tax.php 2 months ago class-wc-order-item.php 1 month ago class-wc-order-query.php 2 months ago class-wc-order-refund.php 1 year ago class-wc-order.php 1 month ago class-wc-payment-gateways.php 2 weeks ago class-wc-payment-tokens.php 3 years ago class-wc-post-data.php 1 month ago class-wc-post-types.php 2 weeks ago class-wc-privacy-background-process.php 1 year ago class-wc-privacy-erasers.php 1 year ago class-wc-privacy-exporters.php 5 years ago class-wc-privacy.php 1 year ago class-wc-product-attribute.php 6 months ago class-wc-product-download.php 1 month ago class-wc-product-external.php 1 year ago class-wc-product-factory.php 5 months ago class-wc-product-grouped.php 1 month ago class-wc-product-query.php 6 months ago class-wc-product-simple.php 1 year ago class-wc-product-variable.php 1 week ago class-wc-product-variation.php 2 weeks ago class-wc-query.php 1 month ago class-wc-rate-limiter.php 4 years ago class-wc-regenerate-images-request.php 2 weeks ago class-wc-regenerate-images.php 2 weeks ago class-wc-register-wp-admin-settings.php 5 years ago class-wc-rest-authentication.php 2 days ago class-wc-rest-exception.php 5 years ago class-wc-session-handler.php 3 weeks ago class-wc-shipping-rate.php 1 year ago class-wc-shipping-zone.php 5 years ago class-wc-shipping-zones.php 2 weeks ago class-wc-shipping.php 1 month ago class-wc-shortcodes.php 2 weeks ago class-wc-structured-data.php 2 weeks ago class-wc-tax.php 1 month ago class-wc-template-loader.php 9 months ago class-wc-tracker.php 1 month ago class-wc-validation.php 1 month ago class-wc-webhook.php 2 weeks ago class-woocommerce.php 1 day ago wc-account-functions.php 2 months ago wc-attribute-functions.php 1 month ago wc-brands-functions.php 1 year ago wc-cart-functions.php 2 weeks ago wc-conditional-functions.php 2 weeks ago wc-core-functions.php 2 weeks ago wc-coupon-functions.php 7 months ago wc-deprecated-functions.php 2 weeks ago wc-formatting-functions.php 2 weeks ago wc-interactivity-api-functions.php 3 months ago wc-notice-functions.php 7 months ago wc-order-functions.php 2 weeks ago wc-order-item-functions.php 3 years ago wc-order-step-logger-functions.php 3 weeks ago wc-page-functions.php 1 month ago wc-product-functions.php 2 weeks ago wc-rest-functions.php 9 months ago wc-stock-functions.php 1 month ago wc-template-functions.php 1 week ago wc-template-hooks.php 1 year ago wc-term-functions.php 2 weeks ago wc-update-functions.php 1 week ago wc-user-functions.php 1 month ago wc-webhook-functions.php 2 months ago wc-widget-functions.php 6 years ago
wc-page-functions.php
322 lines
1 <?php
2 /**
3 * WooCommerce Page Functions
4 *
5 * Functions related to pages and menus.
6 *
7 * @package WooCommerce\Functions
8 * @version 2.6.0
9 */
10
11 defined( 'ABSPATH' ) || exit;
12
13 /**
14 * Replace a page title with the endpoint title.
15 *
16 * @param string $title Post title.
17 * @param int $post_id Optional. The post ID the title belongs to. Passed by the `the_title` filter. Defaults to 0 for backwards compatibility with callers that pass only the title, in which case the queried-object check is skipped (matching the original single-argument behaviour).
18 * @return string
19 */
20 function wc_page_endpoint_title( $title, $post_id = 0 ) {
21 global $wp_query;
22
23 // In block themes the whole template (header, footer, content) renders inside the main
24 // loop, so `the_title` fires for any post title rendered on the page (e.g. a product in a
25 // server-rendered mini-cart) - not just the page's own heading. Only replace the title of
26 // the queried page so an earlier title doesn't consume this one-shot filter.
27 if ( ! is_null( $wp_query ) && ! is_admin() && is_main_query() && in_the_loop() && is_page() && is_wc_endpoint_url() && ( ! $post_id || get_queried_object_id() === $post_id ) ) {
28 $endpoint = WC()->query->get_current_endpoint();
29 $action = isset( $_GET['action'] ) ? sanitize_text_field( wp_unslash( $_GET['action'] ) ) : '';
30 $endpoint_title = WC()->query->get_endpoint_title( $endpoint, $action );
31 $title = $endpoint_title ? $endpoint_title : $title;
32
33 remove_filter( 'the_title', 'wc_page_endpoint_title' );
34 }
35
36 return $title;
37 }
38
39 add_filter( 'the_title', 'wc_page_endpoint_title', 10, 2 );
40
41 /**
42 * Replace the title part of the document title.
43 *
44 * @param array $title {
45 * The document title parts.
46 *
47 * @type string $title Title of the viewed page.
48 * @type string $page Optional. Page number if paginated.
49 * @type string $tagline Optional. Site description when on home page.
50 * @type string $site Optional. Site title when not on home page.
51 * }
52 * @return array
53 */
54 function wc_page_endpoint_document_title_parts( $title ) {
55 global $wp_query;
56
57 if ( ! is_null( $wp_query ) && ! is_admin() && is_main_query() && is_page() && is_wc_endpoint_url() ) {
58 $endpoint = WC()->query->get_current_endpoint();
59 $action = isset( $_GET['action'] ) ? sanitize_text_field( wp_unslash( $_GET['action'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
60 $endpoint_title = WC()->query->get_endpoint_title( $endpoint, $action );
61 $title['title'] = $endpoint_title ? $endpoint_title : $title['title'];
62
63 remove_filter( 'document_title_parts', 'wc_page_endpoint_document_title_parts' );
64 }
65
66 return $title;
67 }
68
69 add_filter( 'document_title_parts', 'wc_page_endpoint_document_title_parts' );
70
71 /**
72 * Retrieve page ids - used for myaccount, edit_address, shop, cart, checkout, pay, view_order, terms. returns -1 if no page is found.
73 *
74 * @param string $page Page slug.
75 * @return int
76 */
77 function wc_get_page_id( $page ) {
78 if ( 'pay' === $page || 'thanks' === $page ) {
79 wc_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.' );
80
81 $page = 'checkout';
82 }
83 if ( 'change_password' === $page || 'edit_address' === $page || 'lost_password' === $page ) {
84 wc_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.' );
85
86 $page = 'myaccount';
87 }
88
89 $page = apply_filters( 'woocommerce_get_' . $page . '_page_id', get_option( 'woocommerce_' . $page . '_page_id' ) );
90
91 return $page ? absint( $page ) : -1;
92 }
93
94 /**
95 * Retrieve page permalink.
96 *
97 * @param string $page page slug.
98 * @param string|bool $fallback Fallback URL if page is not set. Defaults to home URL. @since 3.4.0.
99 * @return string
100 */
101 function wc_get_page_permalink( $page, $fallback = null ) {
102 $page_id = wc_get_page_id( $page );
103 $permalink = 0 < $page_id ? get_permalink( $page_id ) : '';
104
105 if ( ! $permalink ) {
106 $permalink = is_null( $fallback ) ? get_home_url() : $fallback;
107 }
108
109 return apply_filters( 'woocommerce_get_' . $page . '_page_permalink', $permalink );
110 }
111
112 /**
113 * Get endpoint URL.
114 *
115 * Gets the URL for an endpoint, which varies depending on permalink settings.
116 *
117 * @param string $endpoint Endpoint slug.
118 * @param string $value Query param value.
119 * @param string $permalink Permalink.
120 *
121 * @return string
122 */
123 function wc_get_endpoint_url( $endpoint, $value = '', $permalink = '' ) {
124 if ( ! $permalink ) {
125 $permalink = get_permalink();
126 }
127
128 // Map endpoint to options.
129 $query_vars = WC()->query->get_query_vars();
130 $endpoint = ! empty( $query_vars[ $endpoint ] ) ? $query_vars[ $endpoint ] : $endpoint;
131 $value = ( get_option( 'woocommerce_myaccount_edit_address_endpoint', 'edit-address' ) === $endpoint ) ? wc_edit_address_i18n( $value ) : $value;
132
133 if ( get_option( 'permalink_structure' ) ) {
134 if ( strstr( $permalink, '?' ) ) {
135 $query_string = '?' . wp_parse_url( $permalink, PHP_URL_QUERY );
136 $permalink = current( explode( '?', $permalink ) );
137 } else {
138 $query_string = '';
139 }
140 $url = trailingslashit( $permalink );
141
142 if ( $value ) {
143 $url .= trailingslashit( $endpoint ) . user_trailingslashit( $value );
144 } else {
145 $url .= user_trailingslashit( $endpoint );
146 }
147
148 $url .= $query_string;
149 } else {
150 $url = add_query_arg( $endpoint, $value, $permalink );
151 }
152
153 return apply_filters( 'woocommerce_get_endpoint_url', $url, $endpoint, $value, $permalink );
154 }
155
156 /**
157 * Get the tokenized Review Order URL for the given order.
158 *
159 * Top-level rewrite: returns `/review-order/{id}/?key={order_key}` on pretty
160 * permalinks and `/?review-order={id}&key={order_key}` on plain permalinks.
161 * The order key allows guest customers to reach the page without logging in.
162 *
163 * @since 10.8.0
164 * @param WC_Order $order Order object.
165 * @return string
166 */
167 function wc_get_review_order_url( $order ) {
168 if ( ! $order instanceof WC_Order ) {
169 return '';
170 }
171
172 return \Automattic\WooCommerce\Internal\OrderReviews\Endpoint::get_url( $order );
173 }
174
175 /**
176 * Hide or adjust menu items conditionally.
177 *
178 * @param array $items Navigation items.
179 * @return array
180 */
181 function wc_nav_menu_items( $items ) {
182 $logout_endpoint = get_option( 'woocommerce_logout_endpoint', 'customer-logout' );
183
184 if ( ! empty( $logout_endpoint ) && ! empty( $items ) && is_array( $items ) ) {
185 foreach ( $items as $key => $item ) {
186 if ( empty( $item->url ) ) {
187 continue;
188 }
189
190 $path = wp_parse_url( $item->url, PHP_URL_PATH ) ?? '';
191 $query = wp_parse_url( $item->url, PHP_URL_QUERY ) ?? '';
192 $is_logout_link = strstr( $path, $logout_endpoint ) || strstr( $query, $logout_endpoint );
193
194 if ( ! $is_logout_link ) {
195 continue;
196 }
197
198 if ( is_user_logged_in() ) {
199 $items[ $key ]->url = wp_nonce_url( $item->url, 'customer-logout' );
200 } else {
201 unset( $items[ $key ] );
202 }
203 }
204 }
205
206 return $items;
207 }
208 add_filter( 'wp_nav_menu_objects', 'wc_nav_menu_items', 10 );
209
210 /**
211 * Hide menu items in navigation blocks conditionally.
212 *
213 * Does the same thing as wc_nav_menu_items but for block themes.
214 *
215 * @since 9.3.0
216 * @param \WP_Block_list $inner_blocks Inner blocks.
217 * @return \WP_Block_list
218 */
219 function wc_nav_menu_inner_blocks( $inner_blocks ) {
220 $logout_endpoint = get_option( 'woocommerce_logout_endpoint', 'customer-logout' );
221
222 if ( ! empty( $logout_endpoint ) && $inner_blocks ) {
223 foreach ( $inner_blocks as $inner_block_key => $inner_block ) {
224 $url = $inner_block->parsed_block['attrs']['url'] ?? '';
225 $path = wp_parse_url( $url, PHP_URL_PATH ) ?? '';
226 $query = wp_parse_url( $url, PHP_URL_QUERY ) ?? '';
227 $is_logout_link = strstr( $path, $logout_endpoint ) || strstr( $query, $logout_endpoint );
228
229 if ( ! $is_logout_link ) {
230 continue;
231 }
232
233 if ( is_user_logged_in() ) {
234 $inner_block->parsed_block['attrs']['url'] = wp_nonce_url( $inner_block->parsed_block['attrs']['url'], 'customer-logout' );
235 } else {
236 unset( $inner_blocks[ $inner_block_key ] );
237 }
238 }
239 }
240
241 return $inner_blocks;
242 }
243 add_filter( 'block_core_navigation_render_inner_blocks', 'wc_nav_menu_inner_blocks' );
244
245 /**
246 * Fix active class in nav for shop page.
247 *
248 * @param array $menu_items Menu items.
249 * @return array
250 */
251 function wc_nav_menu_item_classes( $menu_items ) {
252 if ( ! is_woocommerce() ) {
253 return $menu_items;
254 }
255
256 $shop_page = wc_get_page_id( 'shop' );
257 $page_for_posts = (int) get_option( 'page_for_posts' );
258
259 if ( ! empty( $menu_items ) && is_array( $menu_items ) ) {
260 foreach ( $menu_items as $key => $menu_item ) {
261 $classes = (array) $menu_item->classes;
262 $menu_id = (int) $menu_item->object_id;
263
264 // Unset active class for blog page.
265 if ( $page_for_posts === $menu_id && isset( $menu_item->object ) && 'page' === $menu_item->object ) {
266 $menu_items[ $key ]->current = false;
267
268 if ( in_array( 'current_page_parent', $classes, true ) ) {
269 unset( $classes[ array_search( 'current_page_parent', $classes, true ) ] );
270 }
271
272 if ( in_array( 'current-menu-item', $classes, true ) ) {
273 unset( $classes[ array_search( 'current-menu-item', $classes, true ) ] );
274 }
275 } elseif ( is_shop() && $shop_page === $menu_id && 'page' === $menu_item->object ) {
276 // Set active state if this is the shop page link.
277 $menu_items[ $key ]->current = true;
278 $classes[] = 'current-menu-item';
279 $classes[] = 'current_page_item';
280
281 } elseif ( is_singular( 'product' ) && $shop_page === $menu_id ) {
282 // Set parent state if this is a product page.
283 $classes[] = 'current_page_parent';
284 }
285
286 $menu_items[ $key ]->classes = array_unique( $classes );
287 }
288 }
289
290 return $menu_items;
291 }
292 add_filter( 'wp_nav_menu_objects', 'wc_nav_menu_item_classes', 2 );
293
294
295 /**
296 * Fix active class in wp_list_pages for shop page.
297 *
298 * See details in https://github.com/woocommerce/woocommerce/issues/177.
299 *
300 * @param string $pages Pages list.
301 * @return string
302 */
303 function wc_list_pages( $pages ) {
304 if ( ! is_woocommerce() ) {
305 return $pages;
306 }
307
308 // Remove current_page_parent class from any item.
309 $pages = str_replace( 'current_page_parent', '', $pages );
310 // Find shop_page_id through woocommerce options.
311 $shop_page = 'page-item-' . wc_get_page_id( 'shop' );
312
313 if ( is_shop() ) {
314 // Add current_page_item class to shop page.
315 return str_replace( $shop_page, $shop_page . ' current_page_item', $pages );
316 }
317
318 // Add current_page_parent class to shop page.
319 return str_replace( $shop_page, $shop_page . ' current_page_parent', $pages );
320 }
321 add_filter( 'wp_list_pages', 'wc_list_pages' );
322