Woocommerce具体价格变动

时间:2015-04-21 23:25:54

标签: woocommerce

我遇到了Woo-commerce的问题,我觉得我非常接近找到解决方案, 但有一个错误:

我的任务是根据以下内容更改woocommerce产品默认价格:用户名,特定产品ID和产品类别。

代码在这里:

`if ( is_user_logged_in() ) {

add_filter('woocommerce_get_price','change_price', 10, 2);
add_filter('woocommerce_get_regular_price','change_price', 10, 2); 
add_filter('woocommerce_get_sale_price','change_price', 10, 2);
}

function change_price($price, $productd){
    $vrednost=$productd->get_sku( );
       $current_user = wp_get_current_user(); //uzimam trenutno logovanog korisnika
            global $wpdb;
            global $mydb;
            global $cena;
            $cena=$productd->price;
            $mydb= new wpdb('root','','wordpress123','localhost'); 
            $mydb->show_errors(); 
            $userna=$current_user->user_login;  
            $paypal_id = $mydb->get_results("select sifra_kupca from wp_prodajno_mjesto WHERE user ='$userna'");
              foreach ($paypal_id as $objs) {
              $sifrovani=$objs->sifra_kupca; 
              }
            $standard_rabat=$mydb->get_results("select standardni_rabat from wp_kupac WHERE sifra_kupca ='$sifrovani'");
              foreach ($standard_rabat as $objs) {
              $ispis=$objs->standardni_rabat;
              }
            $konacnorabat=$ispis;
            $price =intval($productd->price)-((intval($ispis)/100)*$productd->price); 
            $ima=$mydb->get_results("select sifra_kupca from wp_cjenik_kupca WHERE sifra_kupca ='$sifrovani'");       
            foreach ($ima as $objs) {
              $ispis7=$objs->sifra_kupca;
              }
            if ($ispis7==NULL)
            {
             return $price;
             exit;
            }
            $grupa=$mydb->get_results("select grupa_artikala from wp_cjenik_kupca WHERE sifra_kupca ='$sifrovani'");
            foreach ($grupa as $objs) {
              $ispis4=$objs->grupa_artikala;
              }
            if (!($ispis4==NULL))
           {
            global $post;
            $args = array( 'taxonomy' => 'product_cat',);
            $terms = wp_get_post_terms($post->ID,'product_cat', $args);
            $count = count($terms); 
            if ($count > 0) {
              foreach ($terms as $term) {
                $cata=$term->name;
              }
            }
           $sifbaza=$productd->get_sku( );
            $nc=$mydb->get_results("select cjenik_cijena from wp_cjenik_kupca WHERE (sifra_kupca ='$sifrovani' AND sifra_artikla='$sifbaza')");
             foreach ($nc as $objs2) {
              $novacen=$objs2->cjenik_cijena;
              }
            if (!($novacen==NULL))
               {
                 $konacnoprice=$novacen;
                 $rabat2=$mydb->get_results("select cjenik_rabat from wp_cjenik_kupca WHERE (sifra_kupca ='$sifrovani' AND sifra_artikla='$sifbaza')  ");
            foreach ($rabat2 as $objs5) {
              $konacnorabat=$objs5->cjenik_rabat;
              }
               }
             else  {
                  $konacnoprice=$productd->price;
                  $rabat3=$mydb->get_results("select cjenik_rabat from wp_cjenik_kupca WHERE (sifra_kupca ='$sifrovani' AND grupa_artikala='$cata')  ");
            foreach ($rabat3 as $objs5) {
              $konacnirabat=$objs5->cjenik_rabat;
              }
               }

             if (!($konacnirabat==NULL))
               {$price='5000';return $price;
                 exit;}
             else {$price=(intval($konacnoprice)-((intval($konacnorabat)/100)*intval($konacnoprice)));}
                 return $price;
                 exit;
          } 
}
`

现在我遇到一个问题:

`if (!($konacnirabat==NULL))
               {$price='5000';return $price;
                 exit;}`

因此所有价格都在商店页面上正确更改,但是当我添加到购物车特定产品的字段$ konacnirabat不为空时,它会在购物车中给出错误的价格结果。

以下是此处所需的数据库表的屏幕截图: LINK

1 个答案:

答案 0 :(得分:0)

我在过去几天遇到了同样的问题而且我找到了解决方案 - 你应该使用不同的过滤器 - 一个是产品添加到购物车时,另一个是价格来自购物车会话。这是我找到答案的地方:source