小编t0r*_*rxe的帖子

WooCommerce - 从单独的 PHP 文件访问“WC_Order”

我正在使用 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)

html javascript php wordpress woocommerce

4
推荐指数
1
解决办法
2375
查看次数

标签 统计

html ×1

javascript ×1

php ×1

woocommerce ×1

wordpress ×1