Following Display a product custom field only in WooCommerce Admin single orders answer to my previous question, which:
- Adds a Custom SKU Field (ArticleID)
- Saves the Custom SKU (ArticleID) as Hidden Order Item Meta Data
- Saves the Custom SKU (ArticleID) as Hidden Order Item Meta Data for Manual Orders
However, it seems that the last part (for Manual Orders) is causing a conflict with this following other custom code I added for Gateway Fees:
// Assign Card Gateway Percentage Fee to Wholesaler Profiles
add_action('woocommerce_cart_calculate_fees', 'sm_credit_card_fee_role_gateway' );
function sm_credit_card_fee_role_gateway( $cart ){
if ( is_admin() && !defined('DOING_AJAX') )
return;
// Only on checkout page and logged in users
if ( ! ( is_checkout() && ! is_wc_endpoint_url() ) || ! is_user_logged_in() )
return;
$wpuser_object = wp_get_current_user();
$allowed_roles = array('administrator', 'default_wholesaler', 'wholesaler-non-vat-registered', 'wholesaler-ex-vat-registered', 'wholesaler-ex-non-vat-registered', 'shop_manager');
if ( array_intersect($allowed_roles, $wpuser_object->roles) ){
$payment_method = WC()->session->get('chosen_payment_method');
if ( 'cardgatecreditcard' === $payment_method ){
$percentage = 8.25;
$description = 'Credit Card';
}
elseif ( 'cardgatesofortbanking' === $payment_method ){
$percentage = 6;
$description = 'SofortBanking';
}
elseif ( 'cardgategiropay' === $payment_method ){
$percentage = 3.15;
$description = 'GiroPay';
}
elseif ( 'cardgateideal' === $payment_method ){
$percentage = 2.1;
$description = 'iDEAL';
}
}
if ( isset($percentage) ) {
$surcharge = ($cart->cart_contents_total + $cart->shipping_total) * $percentage / 100;
$cart->add_fee( sprintf( __('%s Fee (%s)', 'woocommerce'), $description, $percentage . '%' ), $surcharge, true );
}
}
When I try to update or change the status of an order that has Gateway Fees applied to it, I get this Fatal Error:
So either part 3 of my SKU code needs to be written better, or my gateway fee code needs to be updated. How do I go about troubleshooting this further?
This is the Fatal Error:
Fatal error: Uncaught Error: Call to undefined method WC_Order_Item_Fee::get_product() in …/public_html/wp-content/themes/oceanwp-child/functions.php:920
Stack trace:
#0 …/public_html/wp-includes/class-wp-hook.php(287): action_before_save_order_item_callback(Object(WC_Order_Item_Fee))
#1 …/public_html/wp-includes/class-wp-hook.php(311): WP_Hook->apply_filters(NULL, Array)
#2 …/public_html/wp-includes/plugin.php(478): WP_Hook->do_action(Array)
#3 …/public_html/wp-content/plugins/woocommerce/includes/admin/wc-admin-functions.php(324): do_action('woocommerce_bef...', Object(WC_Order_Item_Fee))
#4 …/public_html/wp-content/plugins/woocommerce/includes/admin/meta-boxes/class-wc-meta-box-order-items.php(54): wc_save_order_items(6053, Array)
#5 …/public_html/wp-includes/class-wp-hook.php(289): WC_Meta_B in …/public_html/wp-content/themes/oceanwp-child/functions.php on line 920
The line Line 920 which is part of "Save SKU "ArticleID" as Hidden Order Item Meta Data for Manual Orders":
$product = $item->get_product(); // Get the WC_Product Object
question from:
https://stackoverflow.com/questions/65892831/display-a-product-custom-field-only-in-woocommerce-admin-single-orders-for-manua 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…