/**
  * Evaluate a cost from a sum/string
  * @param  string $sum
  * @param  array  $args
  * @return string
  */
 protected function evaluate_cost($sum, $args = array())
 {
     include_once 'includes/class-wc-eval-math.php';
     add_shortcode('fee', array($this, 'fee'));
     $this->fee_cost = $args['cost'];
     $sum = do_shortcode(str_replace(array('[qty]', '[cost]'), array($args['qty'], $args['cost']), $sum));
     remove_shortcode('fee', array($this, 'fee'));
     return $sum ? WC_Eval_Math::evaluate($sum) : 0;
 }
 /**
  * Evaluate a cost from a sum/string.
  * @param  string $sum
  * @param  array  $args
  * @return string
  */
 protected function evaluate_cost($sum, $args = array())
 {
     include_once 'includes/class-wc-eval-math.php';
     $locale = localeconv();
     $decimals = array(wc_get_price_decimal_separator(), $locale['decimal_point'], $locale['mon_decimal_point']);
     $this->fee_cost = $args['cost'];
     // Expand shortcodes
     add_shortcode('fee', array($this, 'fee'));
     $sum = do_shortcode(str_replace(array('[qty]', '[cost]'), array($args['qty'], $args['cost']), $sum));
     remove_shortcode('fee', array($this, 'fee'));
     // Remove whitespace from string
     $sum = preg_replace('/\\s+/', '', $sum);
     // Remove locale from string
     $sum = str_replace($decimals, '.', $sum);
     // Trim invalid start/end characters
     $sum = rtrim(ltrim($sum, "\t\n\r\v+*/"), "\t\n\r\v+-*/");
     // Do the math
     return $sum ? WC_Eval_Math::evaluate($sum) : 0;
 }
 /**
  * Evaluate a cost from a sum/string.
  * @param  string $sum
  * @param  array  $args
  * @return string
  */
 protected function evaluate_cost($sum, $args = array())
 {
     include_once WC()->plugin_path() . '/includes/libraries/class-wc-eval-math.php';
     // Allow 3rd parties to process shipping cost arguments
     $args = apply_filters('woocommerce_evaluate_shipping_cost_args', $args, $sum, $this);
     $locale = localeconv();
     $decimals = array(wc_get_price_decimal_separator(), $locale['decimal_point'], $locale['mon_decimal_point'], ',');
     $this->fee_cost = $args['cost'];
     // Expand shortcodes
     add_shortcode('fee', array($this, 'fee'));
     $sum = do_shortcode(str_replace(array('[qty]', '[cost]'), array($args['qty'], $args['cost']), $sum));
     remove_shortcode('fee', array($this, 'fee'));
     // Remove whitespace from string
     $sum = preg_replace('/\\s+/', '', $sum);
     // Remove locale from string
     $sum = str_replace($decimals, '.', $sum);
     // Trim invalid start/end characters
     $sum = rtrim(ltrim($sum, "\t\n\r\v+*/"), "\t\n\r\v+-*/");
     // Do the math
     return $sum ? WC_Eval_Math::evaluate($sum) : 0;
 }
 /**
  * Trigger an error, but nicely, if need be.
  *
  * @param  string $msg
  *
  * @return bool
  */
 private static function trigger($msg)
 {
     self::$last_error = $msg;
     if (defined('WP_DEBUG') && WP_DEBUG) {
         echo "\nError found in:";
         self::debugPrintCallingFunction();
         trigger_error($msg, E_USER_WARNING);
     }
     return false;
 }
示例#5
0
 /** 
  * Calculate order falt rate shipping
  *
  * @support WC 2.4
  */
 public function evaluate_flat_shipping_cost($sum, $args = array())
 {
     include_once WC()->plugin_path() . '/includes/shipping/flat-rate/includes/class-wc-eval-math.php';
     add_shortcode('fee', array($this, 'wcmp_shipping_fee_calculation'));
     $this->wcmp_shipping_fee_cost = $args['cost'];
     $sum = rtrim(ltrim(do_shortcode(str_replace(array('[qty]', '[cost]'), array($args['qty'], $args['cost']), $sum)), "\t\n\r\v+*/"), "\t\n\r\v+-*/");
     remove_shortcode('fee', array($this, 'wcmp_shipping_fee_calculation'));
     return $sum ? WC_Eval_Math::evaluate($sum) : 0;
 }
 private static function trigger($msg)
 {
     self::$last_error = $msg;
     if (!self::$suppress_errors) {
         echo "\nError found in:";
         self::debugPrintCallingFunction();
         trigger_error($msg, E_USER_WARNING);
     }
     return false;
 }