Creating custom page for checkout page does not work

125 Views Asked by At

I am trying to add a content before checkout form in LearnPress so I created a custom checkout page inside child theme using the following code:

function custom_content_before_checkout() {
    // Check if the current page has a post ID of 1463
    if (is_page(1463)) {
        echo '<div class="custom-content">';
        echo '<table>';
        echo '<tr><th>Header 1</th><th>Header 2</th></tr>';
        echo '<tr><td>Data 1</td><td>Data 2</td></tr>';
        echo '<tr><td>Data 3</td><td>Data 4</td></tr>';
        echo '</table>';
        echo '</div>';
    }
}
add_action('learn_press_checkout_before_checkout_form', 'custom_content_before_checkout');

No content showed on the front-page.

I created the above-listed function code and I want to know what's wrong with the code

2

There are 2 best solutions below

0
On

The original code I had though was good but did not work for what I was trying to do and it took me a day to figure out that it's just more simple than I thought.

Here is how I solved the problem:

  1. I filtered the Buy Now inside the course to say "Learn More"
  2. In my child theme, I created this folder structure learnpress/checkout and I copied all the checkout files into the subfolder but only form.php actually works.
  3. I echoed dummy texts just before the checkout form tag in the form.php and the text showed on frontend.

The only problem I wish I could solve is to add the content via the editor but I am okay adding and styling the content inside the child theme code

1
On

Your code seems perfect however ensure that the page ID you are checking with is_page(1463) is correct. Verify that the LearnPress checkout page indeed has an ID of 1463. If it's a different ID, you should use the correct ID.