我正在使用 Javascript 直接从 WooCommerce(通过 Wordpress)中的 functions.php 文件调用 PHP 文件,该文件使用 GitHub 上提供的“PHP XLSXWriter”代码。但是,我无法访问
$order = new WC_Order($order_id);
Run Code Online (Sandbox Code Playgroud)
我可以通过使用直接在 WooCommerce 后面访问此功能吗
require_once('/wp-content/plugins/woocommerce/includes/class-wc-order.php');
Run Code Online (Sandbox Code Playgroud)
?
这是我正在调用的整个 PHP 代码:
$order_id = $_GET['order']; // pull the order info from the URL
$order = new WC_Order($order_id); // this crashes this entire function!
echo $order->shipping_city; // this then fails
echo $order->shipping_country; // and this fails too
// this code doesn't then execute...
$filename = "test.xlsx";
header('Content-disposition: attachment; filename="'.XLSXWriter::sanitize_filename($filename).'"');
header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
header('Content-Transfer-Encoding: binary');
header('Cache-Control: must-revalidate');
header('Pragma: public');
$rows = …Run Code Online (Sandbox Code Playgroud)