WooCommerce优惠券从正常价格计算



我需要为"朋友"客户提供功能,他们可以以更优惠的价格获得产品。基于用户角色的解决方案不是我想要的,客户希望它与优惠券一起使用。他们向客户提供优惠券代码,例如,他们从某些产品的常规价格中获得 8 欧元的折扣。问题是,默认情况下,WooCommerce优惠券从最低价格计算它。如果设置了销售价格,则此计算是错误的,客户会得到它太便宜。基本上,我希望优惠券给某些产品固定的"朋友"价格。

我一直在谷歌上搜索,找不到现成的解决方案。欢迎任何如何解决此问题的建议。

我已经检查了多个插件,但没有一个满足我的要求。

添加到函数.php。基于此代码 https://brilliantinfo.net/apply-coupon-discount-on-regular-price-in-woocommerce/

针对fixed_product优惠券类型进行了修改。如果您需要它仅适用于特定的优惠券,那么我可以为此进行修改。(目前,这将适用于使用的任何fixed_product优惠券(

    add_action( 'woocommerce_before_calculate_totals', 'adjust_cart_coupon', 10, 1);
    function adjust_cart_coupon( $cart_object) {
      global $woocommerce;
      if ( is_admin() && ! defined( 'DOING_AJAX' ) ){
        return;
      }
      $coupon = False;
      if ($coupons = WC()->cart->get_applied_coupons()  == False ) {
          $coupon = False;
      } else {
        foreach ( WC()->cart->get_applied_coupons() as $code ) {
          $coupons1 = new WC_Coupon( $code );
          if ($coupons1->type == 'fixed_product'){
            $coupon = True;
          }
        }
      }
      if ($coupon == True){
        foreach ( $cart_object->get_cart() as $cart_item ){
          $price = $cart_item['data']->regular_price;
          //sets cart item to use regular price and not sale price
          $cart_item['data']->set_price( $price );
        }
      }
    }

WooCommerce插件的折扣规则可能符合您的要求。

有了它,您可以将优惠券或任何折扣规则应用于特定客户。

还有一个设置,即根据销售价格或正常价格应用折扣

最新更新