Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 获取与商业订单项目相关的产品自定义字段_Php_Wordpress_Woocommerce_Custom Fields_Hook Woocommerce - Fatal编程技术网

Php 获取与商业订单项目相关的产品自定义字段

Php 获取与商业订单项目相关的产品自定义字段,php,wordpress,woocommerce,custom-fields,hook-woocommerce,Php,Wordpress,Woocommerce,Custom Fields,Hook Woocommerce,我试图从结帐/订单小计前面的自定义字段添加数据,但未显示get\u post\u meta。我尝试了$product->get_ID(),$post_ID和获取_ID() 代码中缺少一些参数和错误…请尝试以下操作: add_filter( 'woocommerce_order_formatted_line_subtotal', 'custom_field_test', 10, 3 ); function custom_field_test( $subtotal, $item, $order ){

我试图从结帐/订单小计前面的自定义字段添加数据,但未显示
get\u post\u meta
。我尝试了
$product->get_ID()
$post_ID
获取_ID()


代码中缺少一些参数和错误…请尝试以下操作:

add_filter( 'woocommerce_order_formatted_line_subtotal', 'custom_field_test', 10, 3 );
function custom_field_test( $subtotal, $item, $order ){ 
    $product = $item->get_product(); // The instance of the WC_Product Object

    if( $custom_field =  get_post_meta( $product->get_id(), 'custom_field', true ) ) {
        $subtotal = $custom_field . ' '. $subtotal;
    }
    return $subtotal;
}

代码进入活动子主题(或活动主题)的function.php文件。测试成功。

我两次遇到这个错误:Uncaught ArgumentCounter错误:参数太少,无法实现自定义字段测试(),1个传入您太棒了!!非常感谢。
add_filter( 'woocommerce_order_formatted_line_subtotal', 'custom_field_test', 10, 3 );
function custom_field_test( $subtotal, $item, $order ){ 
    $product = $item->get_product(); // The instance of the WC_Product Object

    if( $custom_field =  get_post_meta( $product->get_id(), 'custom_field', true ) ) {
        $subtotal = $custom_field . ' '. $subtotal;
    }
    return $subtotal;
}