php - woocommerce override of product -


i have problem following code when make price variable function doesn't work when hardcode price works. (note in testing face , haven't worried security)

this, down't work:

function add_custom_price( $cart_obj ) {     global $product, $woocommerce ,$wpdb;      if ( isset( $_post['fra'] ) ){         $globals['$_fra'] = urldecode( $_post["fra"] );     } else {         $globals['$_fra'] = "";     }     if ( isset( $_post['til'] ) ){         $globals['$_til'] = urldecode($_post["til"]);     } else {         $globals['$_til'] = "";     }     if ( $globals['$_til'] !="" && $globals['$_fra'] !="" ){          $t1 = urldecode( $globals['$_til'] );         $t2 = urldecode( $globals['$_fra']);          $objarray = $wpdb->get_results("select $t1 test_priser city = '$t2'");          if ( isset($objarray[0]->$t1) ){             $priser = explode("/",$objarray[0]->$t1);             if ( !isset($priser[1]) ){                 $priser[1] = intval($priser[0]);             }         }          echo "priser[1] = ".$priser[1]; //this outputs expected value     }     if ( is_admin() && ! defined( 'doing_ajax' ) ){        return;     }     foreach ( $cart_obj->get_cart() $key => $value ) {         $value['data']->set_price( $priser[1] );     }  } 

when add line, , override variable, works:

$priser[1] = 1000; 

i quite confused problem might be.

for else might stumble upon this. seems need pass variable price in session works.

you can find answer here: custom price on woocommerce product


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -