How to call a woocommerce variable to another php file?

1

Good morning, I have the following code in functions.php :

include('popup.php');
add_action( 'woocommerce_single_product_summary', 'boton_sub_producto_single', 6 );
function boton_sub_producto_single() {
     global $product;     
      $nombre =  $product->get_title();        

            if ( ! $product->is_in_stock() || ! $product->is_purchasable() ){

                echo '<button type="button" class="button btn-info btn-lg" data-toggle="modal" data-target="#myModal" data-backdrop="static">Encuentra tu producto</button>';
         }
            return $product;       
   }

This shows me a button on the individual products page, all right here, I try to call the name of the product with the following variable $nombre = $product->get_title(); if I write there is same echo $nombre; shows me the name of the product effectively.

Now when I click on the function button this opens a "bootstrap modal" popup that I have on another page called popup.php with the following code:

<!DOCTYPE html>
<html lang="en">
<body>

<div class="container">
    <!-- Trigger the modal with a button -->
 <!-- <button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>-->

  <!-- Modal -->
  <div class="modal fade" id="myModal" role="dialog">
    <div class="modal-dialog">

      <!-- Modal content-->
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title">Modal Header</h4>
        </div>
        <div class="modal-body">
          <p>Some text in the modal.</p><?php 

          echo $nombre; ?>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
      </div>

    </div>
  </div>

</div>

</body>
</html>

I want to print the name of the product here

<p>Some text in the modal.</p><?php 

          echo $nombre; ?>

But does not it show me anything - any way I could print the name of the product inside the popup?

    
asked by Guille Figueroa 08.07.2017 в 18:37
source

1 answer

0

I do not know so much about Wordpress, but I know that almost everything is global there: /

You have several options assuming you can use the global variable $product .

You could simply do echo $product->get_title() .

You can also use a woocommerce function: echo woocommerce_template_single_title(); , but it comes with some HTML (usually an H1).

In general you could use several of the functions of WP that are going to look for the title of the post (product in this case), although being a popup I do not know if the context is lost.

Another option in case that none of the above works would be that you create a function that obtains the id of the product and later its name.

    
answered by 08.07.2017 в 19:00