I am getting bool(false)
as a return making calls for a product, using the product ID. Depending on which code I use, I have also had NULL
and 0
returns but never any product data.
I have tried...
$_pf = new WC_Product_Factory();
$product = $_pf->get_product($id);
$_pf = new WC_Product_Factory();
$product = $_pf->wc_get_product($id);
$product = new WC_Product('1651');
I have even tried calling all the way back to WC()->
.
I have tried the above code in functions.php
. I am also having issues with the child div file not over riding the parent div file, so I have placed this code in the parent div file. That issue is for another time, I just need to get a simple call to the product to go through.
<script>
function getAJAX() {
jQuery.ajax({
type: "post",
url: "/wp-admin/admin-ajax.php",
data: "action=get_Title&id=1651",
success: function (data) {
console.log(data);
}
});
} // End function for getAJAX.
var button = document.getElementById("ajax_button");
button.addEventListener("click", getAJAX);
</script>
This is the AJAX call from the template, content-single-product.php. I do not think there is any issues here. I am getting data returned.
add_action("wp_ajax_get_Title", "get_Title");
add_action("wp_ajax_nopriv_get_Title", "get_Title");
function get_Title() {
$id = $_REQUEST['id'];
$_pf = new WC_Product_Factory();
$product = $_pf->get_product($id);
echo $product;
die();
}
Above is some code I have been using to test. Last thing I tried and still getting bool(false)
.
Yes, that is a valid product ID. I was just testing out connecting to a product and pulling out the title, or something, before I start coding for all the pieces of data I need to pull from the product.
This is a multi-site platform, and the AJAX calls and calls to woocommerce products are working on other pages within the very site I am working on, but will not pull anything on the project I am working on.
I am very new to woocommerce and WP, so any help here is greatly appreciated.
int
returns nothing, an actual blank response. Thank you for the suggestion Stephan but it did not fix the issue at this time. Back to the drawing board, any other suggestions? Thank you again.