php - Woocommerce 错误 ET_WC_Order::get_total()
问题描述
我将 Woocommerce 与我的 Wordpress 主题一起使用。该网站正在销售服务。模板开发人员支持已死,他们说 woocommerce 兼容性但有一个小错误我需要自己找到修复但我不知道该怎么做。
当客户尝试将信用添加到他的帐户时,他选择了该值并转到显示 woocommerce 支付网关的下一个屏幕,它们被列出,但“支付”按钮不存在。当我查看 Wordpress wp-content 调试日志时,出现以下错误:
[23-Jul-2018 10:15:58 UTC] PHP 严格标准:ET_WC_Order::get_total() 的声明应与 /home/admin/public_html/mysite 中的 WC_Abstract_Order::get_total($context = 'view') 兼容.com/wp-content/themes/mysite.com/includes/aecore/wc_integration/payment/ET_WC_Order.php 第 3 行 [23-Jul-2018 10:15:58 UTC] PHP 严格标准:ET_WC_Package::get_sku 声明() 应该与 /home/admin/public_html/mysite.com/wp-content/themes/mysite.com/includes/aecore/wc_integration/payment/ET_WC_Package 中的 WC_Product::get_sku($context = 'view') 兼容。第 4 行的 php
ET_WC_Order.php 内容:
<?php if(class_exists("WC_Abstract_Order")) {
class ET_WC_Order extends WC_Abstract_Order
{
protected $etOrder;
protected $cancel_url = "";
protected $received_url = "";
public function __construct($order = '')
{
$this->post_type = 'order';
$this->prices_include_tax = get_option('woocommerce_prices_include_tax') == 'yes' ? true : false;
$this->tax_display_cart = get_option('woocommerce_tax_display_cart');
$this->display_totals_ex_tax = $this->tax_display_cart == 'excl' ? true : false;
$this->display_cart_ex_tax = $this->tax_display_cart == 'excl' ? true : false;
$this->init($order);
}
public function get_refunds()
{
return array();
}
public function get_total_refunded()
{
return 0;
}
/**
* Init
*
* @param int|object|WC_Order $order
*/
protected function init($order)
{
if (is_numeric($order)) {
$this->id = absint($order);
$this->post = get_post($order);
$this->get_order($this->id);
} elseif ($order instanceof ET_WC_Order) {
$this->id = absint($order->id);
$this->ID = absint($order->id);
$this->post = $order->post;
$this->etOrder = $order->etOrder;
$this->populate($order->etOrder);
} elseif ($order instanceof AE_Order) {
$payData = $order->generate_data_to_pay();
$order->ID = $payData["ID"];
$this->etOrder = $order;
$this->populate($order);
// Billing email cam default to user if set
if (empty($this->billing_email) && !empty($this->customer_user)) {
$user = get_user_by('id', $this->customer_user);
$this->billing_email = $user->user_email;
}
} elseif ($order instanceof WP_Post || isset($order->ID)) {
$this->id = absint($order->ID);
$this->post = $order;
$this->get_order($this->id);
}
}
public function get_order($id = 0)
{
if (!$id) {
return false;
}
$this->etOrder = new AE_Order($id);
if ($this->etOrder) {
$payData = $this->etOrder->generate_data_to_pay();
$this->etOrder->ID = $payData["ID"];
$this->populate($this->etOrder);
return true;
}
return false;
}
/**
* Populate the order, like convert method
*
* @param mixed $result
*/
public function populate($result)
{
$orderData = $result->get_order_data();
// Standard post data
$this->id = $result->ID;
$this->order_date = $orderData['created_date'];
$this->modified_date = $orderData['created_date'];
$this->customer_message = '';
$this->customer_note = '';
$this->post_status = $orderData['status'];
// Billing email cam default to user if set
if (empty($this->billing_email) && !empty($this->customer_user)) {
$user = get_user_by('id', $this->customer_user);
$this->billing_email = $user->user_email;
}
$this->cancel_url = et_get_page_link('process-payment', array('paymentType' => $orderData['payment']));
$this->received_url = et_get_page_link('process-payment', array('paymentType' => $orderData['payment']));
}
public function get_shipping_address()
{
return "";
}
/**
* Get item of order
*
* @param string $type
* @return array
*/
public function get_items($type = '')
{
if (empty($type)) {
$type = array('line_item');
}
if (!is_array($type)) {
$type = array($type);
}
$type = array_map('esc_attr', $type);
$items = array();
if (in_array('line_item', $type)) {
$orderData = $this->etOrder->get_order_data();
if (isset($orderData["products"])) {
$index = 0;
foreach ($orderData["products"] as $id => $product) {
$items[$index]['name'] = $product['NAME'];
$items[$index]['product_id'] = $product['ID'];
$items[$index]['type'] = "line_item";
$items[$index]['qty'] = $product['QTY'];
$items[$index]['tax_class'] = '';
$items[$index]['line_subtotal'] = $product['AMT'];
$items[$index]['line_subtotal_tax'] = '0';
$items[$index]['item_meta'] = array();
$index++;
}
}
}
return $items;
}
/**
* Get total of order
* @author : Nguyễn Văn Được
* @return mixed
*/
public function get_total()
{
$orderData = $this->etOrder->get_order_data();
$total = $orderData["total"];
return $total;
}
/**
* Get order currency
* @author : Nguyễn Văn Được
* @return mixed
*/
public function get_order_currency()
{
$orderData = $this->etOrder->get_order_data();
return $orderData["currency"];
}
/**
* Get products from product item
* @author : Nguyễn Văn Được
*
* @param mixed $item
*
* @return bool|\ET_WC_Package
*/
public function get_product_from_item($item)
{
if (!empty($item['product_id'])) {
$_product = new ET_WC_Package($item['product_id']);
} else {
$_product = false;
}
return $_product;
}
public function get_checkout_order_received_url()
{
return $this->received_url;
}
public function set_checkout_order_received_url($received_url)
{
$this->received_url = $received_url;
}
public function get_cancel_order_url($redirect = '')
{
return $this->cancel_url;
}
public function set_cancel_order_url($cancel_url)
{
$this->cancel_url = $cancel_url;
}
/**
* Update order status
*
* @param string $new_status
* @param string $note
*/
public function update_status($new_status, $note = '', $manual = false)
{
if (!$this->id) {
return;
}
// Standardise status names.
$new_status = 'wc-' === substr($new_status, 0, 3) ? substr($new_status, 3) : $new_status;
$old_status = $this->get_status();
switch (strtoupper($new_status)) {
case 'COMPLETED':
case 'PUBLISH':
$this->post_status = 'publish';
break;
case 'PROCESSING' :
case 'ON-HOLD':
$this->post_status = 'pending';
break;
case 'CANCELLED' :
$this->post_status = 'draft';
break;
default:
$this->post_status = 'draft';
break;
}
$this->etOrder->post_status = $this->post_status;
$log = new WC_Logger();
$log->add('paypal', "Our Debug : " . $this->post_status);
wp_update_post(array('ID' => $this->etOrder->ID, 'post_status' => $this->post_status));
}
public function needs_shipping_address()
{
return false;
}
public function is_editable()
{
return parent::is_editable(); // TODO: Change the autogenerated stub
}
public function get_qty_refunded_for_item($item_id, $item_type = 'line_item')
{
$qty = 0;
return $qty;
}
public function get_total_refunded_for_item($item_id, $item_type = 'line_item')
{
$total = 0;
return $total * -1;
}
}
}
ET_WC_Package.php 内容:
<?php
if(class_exists("WooCommerce")) {
class ET_WC_Package extends WC_Product
{
protected $etPaynentPackage;
function __construct($product, $arg = array())
{
$this->product_type = 'pack';
parent::__construct($product);
}
public function get_sku()
{
return $this->post->ID;
}
public function is_virtual()
{
return true;
}
public function needs_shipping()
{
return false;
}
public function get_permalink() {
return get_permalink( $this->id );
}
}
}
解决方案
PHP 严格标准:ET_WC_Order::get_total() 的声明应与 WC_Abstract_Order::get_total($context = 'view') 兼容
get_total()
将函数更改ET_WC_Order.php
为
public function get_total($context = 'view')
{
$orderData = $this->etOrder->get_order_data();
$total = $orderData["total"];
return $total;
}
PHP 严格标准:ET_WC_Package::get_sku() 的声明应与 WC_Product::get_sku($context = 'view') 兼容
get_sku()
将函数更改ET_WC_Package.php
为
public function get_sku($context = 'view')
{
return $this->post->ID;
}
推荐阅读
- python - 无法在 Powershell 中找到或运行我的脚本
- sql - Snowflake SQL 错误 - 函数“-”的参数类型无效:(TIMESTAMP_NTZ(9), TIMESTAMP_NTZ(9))
- machine-learning - 将 Pytorch 图像分类器转换为 mlmodel 时出现问题:无论 img 如何,都返回相同的 softmax 输出
- excel - VBA 性能
- r - 观星者省略了一些我没有指定的系数
- java - 如何使代码在递归后只运行一次?
- vba - 选择“收件箱”时如何折叠特定的收件箱组并展开所有其他组?
- python - 在 Pandas 数据框中添加聚合/摘要行
- angularjs - Md-select multiple 在 md-menu 中不关闭
- python - 无法修补魔法属性