How can you determine the current endpoint and sub-endpoint in WooCommerce?

Suppose the URL is:

https://example.com/my-account/edit-address/billing
https://example.com/my-account/edit-address/shipping

I am attempting to determine if the current displayed endpoint is billing or shipping using the is_wc_endpoint_url function. However, this method does not seem effective.

I have tested the following code snippets without success:

if(is_wc_endpoint_url('billing')){
  ...
}

is_wc_endpoint_url('edit-address/billing'){
  ...
}

All of the above attempts are unsuccessful. Surprisingly, the below mentioned code works perfectly for the edit-address endpoint;

is_wc_endpoint_url('edit-address'){
  ...
}

Are billing and shipping considered sub-endpoints of edit-address? How can I verify this?

Answer №1

Have you considered using the function is_wc_endpoint_url() along with $wp to verify whether the current page is the endpoint for the billing address?

  global $wp;
$current_url = home_url(add_query_arg(array(),$wp->request));
$billing = home_url('/account/edit-address/billing');

if(is_wc_endpoint_url('edit-address') && $current_url === $billing){ 
   echo 'The current page being displayed is the billing section.';
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

$_POST is unable to read POST parameters when using AJAX

I've been facing an issue with sending data to my PHP script. Interestingly, everything works smoothly when using POSTMAN and the results are displayed correctly. However, when attempting to send the data through AJAX in my HTML project, the PHP scrip ...

Mastering Regular Expressions with PHP

Hello, I am currently working on creating a Regular Expression that will replace any word enclosed in pound signs (#) with a URL. I want it to function similar to Twitter hashtags, but my current expression only works for English words. If a post is made ...

Updating serialized data in PHP

I am seeking assistance with unserializing and updating the array values in PHP. My goal is to unserialize a string, update the value for a specific key while preserving the other values, and then reserialize the array. So far, my attempts have been unsucc ...

Looking for a way to combine and calculate duplicate values in a MySQL query, then sort them based on their

I have 2 tables. In 'table_a', there are multiple columns that need to be combined into one result: 'table_a' (time, col_1, col_2,....col_50) //'col_[1-50]' columns contain '$id' example values for col_1: (1000, 10 ...

Organizing outcome searches through ajax

I have a result table displayed on the left side https://i.stack.imgur.com/otaV4.png https://i.stack.imgur.com/pp9m0.png My goal is to transform it into the format shown on the right side of the table In a previous inquiry found here, @Clayton provided ...

Problem with Elysia Cron in Drupal 7: Invalid key causing Cron to fail

Our Drupal websites utilize Elysia Cron and have an external CRON tab set up to access the CRON URL at . Unfortunately, upon checking the logs, we encountered an error message stating: "Cron could not run because an invalid key was used". ...

For the past 48 hours, I have been facing a challenging issue that seems to be quite straightforward - updating images in PHP with Laravel

I've been working on developing an e-commerce platform and I've encountered a problem that has me stuck for the past 2 days. It seems like it might be something simple, but I just can't seem to find the solution. Could you lend me a hand wit ...

A setter that stands alone, waiting for its matching getter

Similar Question: What are practical applications of write-only properties? Having a getter without a setter is expected, creating a read-only property. Makes sense, no issue here. However, I'm faced with code that has setters but lacks getters, ...

Connect the blade.php file with CSS in Laravel version 5.x

I placed my view.blade.php file in resources\views\admin\login\view.blade.php and used the following code to link it to the CSS file: <link href="{!! HTML::style('css/style.css') !!}" rel="stylesheet">. My CSS file is lo ...

Using Query strings in JavaScript: A Quick Guide

I recently completed a calculator project with only two pages. However, I am struggling to figure out how to pass input field values from one page to another. Despite trying multiple methods, nothing seems to be working. Does anyone know how to successful ...

It is not possible for $_GET to loop through an array

I have a list of values called dataId obtained from checkbox selections, and I want to send it via a GET AJAX request: dataId = 1, 2, 16, 15, 17, 3, 14, 5, 9, 11; URI = "<?php echo site_url('Terpasang/Update_Kebutuhan_ke_Terpasang')?>"; $. ...

Transferring information from a form to a PHP file via the POST method

Looking for help with passing and utilizing sent and id values between form.php and test.php using Ajax. Here is the code I've been working on: <html> <head> <script> function showUser(str) { if (str=="") { document. ...

finding a pair of double quotes with preg_match

I am trying to match a specific pattern in order to extract the word "target." INPUT TYPE="HIDDEN" NAME="TITLE" VALUE="target " Despite my efforts, I have been unsuccessful so far. preg_match('@(?:<INPUT TYPE="HIDDEN" NAME="TITLE" VALUE=")(. ...

No response being received from Ajax request

Having some trouble with an ajax function I developed for a small project. The issue lies in running the code inside the .done() function. This function is supposed to receive a json object from php (which I am obtaining a response via cURL), but it appear ...

Retrieving a variable from a post form using phpseclib NET/SSH2

How can I pass POST variables into my $ssh->exec command? I want the $domain and $password values to be utilized within the adduser command. I am working on a CentOS 7 server with PHP 7.3. While I am able to echo out the variables, I am struggling to have ...

PHP - Is there a way to transfer data between two PHP files using variables?

I have two unique files named index.php and get.php. The purpose of index.php is to serve as a web page. However, get.php is not designed to be accessed by the user as it is not intended to function as a web page; its sole purpose is to echo some HTML cod ...

Issue with custom annotations in Symfony 4: @ORMEntity not recognized

While working on the development of my CMS, I encountered a specific issue that I need assistance with. The error message I am facing is as follows: [Semantical Error] The annotation "@Doctrine\ORM\Mapping\Entity" in class ScyLabs\G ...

Ajax is known for its uncanny ability to consistently encounter errors

Having trouble with my ajax call, it keeps ending up in the error part. Can someone please assist me and point out where I may be going wrong? I even checked by writing the final value to a text file and everything seemed fine. The URL is correct as well. ...

Neo4j PHP Graphaware error: '400 Bad Content-Type header' encountered

When running the following test case (assuming correct password) <?php require_once "vendor/autoload.php"; use GraphAware\Neo4j\Client\ClientBuilder; $client = ClientBuilder :: create() -> addConnection("default", "http:/ ...

Utilizing Bootstrap Modal to Display PHP Data Dynamically

Modals always pose a challenge for me, especially when I'm trying to work with someone else's code that has a unique take on modals that I really appreciate (if only I can make it function correctly). The issue arises when the modal is supposed ...