So I created a jquery script to fetch a data upon selecting from the drop down box, and show the amount of stocks but the thing is, it says: Fatal error: Class 'WC_Product_Variable' not found.
But when testing things out to directly run the file, it works, but when being fetched by jquery and show it so the page wont refresh it's not showing anything but instead throwing an error.
change.js
$(document).ready(function(){ $( ".selectProductClass" ) .on('change', function () { var str = ""; $( "select.selectProductClass option:selected" ).each(function() { str += $( this ).val() + " "; }); $.post('../wp-content/plugins/pos-extension-supplier/admin/pos-extension-product-stock.php"); ?>', {str:str}, function(data) { $('div.stocksLeftInHere').text(data); }); }); });
product-stock.php
$product_id=$_POST['str']; echo $product_id; $handle=new WC_Product_Variable($product_id); $variations1=$handle->get_children(); foreach ($variations1 as $value) { $single_variation=new WC_Product_Variation($value); $branch_name = implode(" / ", $single_variation->get_variation_attributes()); if($branch_name == "Warehouse") { echo "".$single_variation->stock.""; echo ""; echo "stock."'>"; } }
The problem is, it doesn't found the WC_Product_variable, Fatal error: Class 'WC_Product_Variable' not found.