I am trying to add an action to recalculate the total cart price with modified price for customers with discounts. The code in located in my themes function.php. The problem is that if I enable add_action( ‘woocommerce_before_calculate_totals’, ‘bis_recalc_price’, 10 ); I get an error PHP Fatal error: Uncaught Error: Undefined constant “API_CUSTOMER_NAME”. The constant is defined in wp-config.php. If I define the constant again within the function then I get a new error: PHP Fatal error: Uncaught Error: Call to undefined function get_meta() This only happens when I try to enable woocommerce_before_calculate_totals. Also the problem only occurs in this function. All the other function in the file work fine.
add_action( 'woocommerce_before_calculate_totals', 'bis_recalc_price', 10 );
function bis_recalc_price( $cart_object ){
$customerArray=api_authCustomer(API_CUSTOMER_NAME, API_PASSORD);
foreach ($cart_object->get_cart() as $hash => $value) {
if(isset($_COOKIE['wt_customerID'])) {
$_product = $value['data'];
$is_on_sale = $value['data']->is_on_sale();
$bisProductArray = api_getProductByIDonly($_product->get_sku(), $customerToken);
$SellPerText = $bisProductArray[0][0]['SellPerText'];
$custID = $_COOKIE['wt_customerID'];
$prodID = get_meta('bis_prodID', true);
$prodID = get_post_meta($value['data']->get_id(),'bis_prodID', true);
if ($prodID > 0) {
$priceStockArray = api_customerpriceandstocklevel($custID, $prodID, $SellPerText, $customerToken);
$customer_price=$priceStockArray[0]['CustomerPrice'][0]['UnitSellPrice'];
if ( $is_on_sale and ($_product->get_sale_price()>0)) {
if ($customer_price > $_product->get_sale_price()) {
$customer_price = $_product->get_sale_price();
}
}
$value['data']->set_price($customer_price);
}
}
}
}
2