Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/297.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 - Fatal编程技术网

Php 商业凌驾于购物车价格之上

Php 商业凌驾于购物车价格之上,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,我目前在WooCommerce工作。下面的函数挂钩到“计算合计之前的woocommerce”并更改产品的值。这适用于简单产品,但不适用于变体: add_action( 'woocommerce_before_calculate_totals', 'wwp_variable_add_cart_price' ); function wwp_variable_add_cart_price( $cart_object ) { $current_user = new WP_User(wp_get_curr

我目前在WooCommerce工作。下面的函数挂钩到“计算合计之前的woocommerce”并更改产品的值。这适用于简单产品,但不适用于变体:

add_action( 'woocommerce_before_calculate_totals', 'wwp_variable_add_cart_price' );
function wwp_variable_add_cart_price( $cart_object ) {
$current_user = new WP_User(wp_get_current_user()->id);
$user_roles = $current_user->roles;
foreach ($user_roles as $roles) {
    if ($roles == 'administrator'){
        foreach ( $cart_object->cart_contents as $key => $value ) {
            $wholesale = get_post_meta( $value['product_id'], '_wholesale_price', true );
            if ($wholesale){    
            $value['data']->price = $wholesale;
            }
}}}}

我需要做一些不同的变化吗?或者上述方法是否有效?

我通过添加以下代码行来解决此问题:

$wholesalev = get_post_meta( $value['data']->variation_id, '_wholesale_price', true );