// Display custom field Orders edit page
add_action('woocommerce_before_order_itemmeta', 'storage_location_of_order_items', 10, 3);
function storage_location_of_order_items($item_id, $item, $product)
{
// Only on backend order edit pages
if (!(is_admin() && $item->is_type('line_item'))) return;
// Get your '_laoriiul' value (replace the slug by yours below)
$custom_ladu = get_post_meta($product->get_id(), '_laoriiul', true); //Error message: "Uncaught Error: Call to a member function get_id() on bool in functions.php:211" - when product not aviable (line 211)
if (isset($custom_ladu)) { // only show the custom SKU if it's set
echo "<br>" . wp_kses_post("Laoriiul: $custom_ladu"); // change this line if needed
}
}
当产品不再在商店中时 - 当不再获得 ID 时,就会出现问题/错误。如何控制获取id之前是否存在产品id?尝试了不同的解决方案,但没有任何帮助。有人帮我吗?
我无法重现该错误,但从错误开始,我想您可以使用以下内容。
method_exists ( mixed $object , string $method_name ) : bool
检查给定对象中是否存在类方法。
您是否使用过旧版本的 WooCommerce 或 Wordpress?
// Display custom field Orders edit page
function storage_location_of_order_items( $item_id, $item, $product ) {
// Only on backend order edit pages
if (!(is_admin() && $item->is_type('line_item'))) return;
// Checks if the class method exists
if ( method_exists( $product, 'get_id' ) ) {
// Get product id
$product_id = $product->get_id();
// Get your '_laoriiul' value (replace the slug by yours below)
$custom_ladu = get_post_meta( $product_id, '_laoriiul', true);
if ( isset( $custom_ladu ) ) { // only show the custom SKU if it's set
echo "<br>" . wp_kses_post( $custom_ladu ); // change this line if needed
}
}
}
add_action('woocommerce_before_order_itemmeta', 'storage_location_of_order_items', 10, 3);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)