Adding php on single page and not via global header

hello,

without using the header file, is there a way to put this code in a single page?

<?php
$product_1_price = wc_get_product(2975)->get_regular_price();
$product_2_price = wc_get_product(2979)->get_regular_price();
$product_3_price = wc_get_product(2988)->get_regular_price();
?>

Hi @fxground,

Thank you for reaching out to us. This can be done using WordPress hooks, to find out X and Pro Specific Actions and Filters please see https://theme.co/docs/actions-filters-and-hooks

Because this requires a template change, I’d advise that you setup a child theme. This allows you to make code changes that won’t be overwritten when a theme update is released. After your child theme is setup, please review how we recommend making template changes in Customization Best Practices.

Please note that custom development is outside the scope of support we can offer. You may wish to consult a developer to assist you with this. X / Pro is quite extensible with child themes, so there are plenty of possibilities.

Thanks for understanding. Take care!

Thanks, not sure if i’m not understanding or you’re not but i’m trying to find out how to do this on one specific page and NOT a global thing (so not using the child theme which i already have setup) … is it possible to only do this on one specific page?

Hey @fxground,

Since you’ve a PHP code and it can only be added through a template change and the best way of doing this would be using the child theme. using conditional tags you can insert your PHP code on a specific page e.g using is_page( 42 ) function you can target the specific page that has the ID 42

if( is_page( 42 )){
 your specific code for this page here..
}

You can learn more about this function here https://developer.wordpress.org/reference/functions/is_page/ and here’s a thread that might help you in this regard https://stackoverflow.com/questions/60165517/how-to-insert-page-post-specific-script-in-header-and-footer-in-wordpress

Please note that custom development is outside the scope of support we can offer. You may wish to consult a developer to assist you with this. X / Pro is quite extensible with child themes, so there are plenty of possibilities.

Hope this helps!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.