Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/385.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 吴邦管理_Javascript_Php_Wordpress_Woocommerce_Custom Wordpress Pages - Fatal编程技术网

Javascript 吴邦管理

Javascript 吴邦管理,javascript,php,wordpress,woocommerce,custom-wordpress-pages,Javascript,Php,Wordpress,Woocommerce,Custom Wordpress Pages,有人知道我怎么能把coupoun做成这样,或者以前做过吗 我想打%的折扣 您可以将coupoun添加到onsale产品中,但它应该使用该产品的完整价格并从那里开始计算,而不是说它会产生双重折扣(onsale产品+基于百分比的折扣(使用coupoun)) 有什么想法,怎么做吗?是的,可以在functions.php文件中添加此代码。在下面的代码中,“五十”是所用优惠券的名称。在woo commerce中创建基于%的优惠券 add_filter('woocommerce_coupon_get_dis

有人知道我怎么能把coupoun做成这样,或者以前做过吗

我想打%的折扣

  • 您可以将coupoun添加到onsale产品中,但它应该使用该产品的完整价格并从那里开始计算,而不是说它会产生双重折扣(onsale产品+基于百分比的折扣(使用coupoun))

  • 有什么想法,怎么做吗?

    是的,可以在functions.php文件中添加此代码。在下面的代码中,“五十”是所用优惠券的名称。在woo commerce中创建基于%的优惠券

    add_filter('woocommerce_coupon_get_discount_amount', 'woocommerce_discount_from_the_original_price', 10, 5 );
    
    function woocommerce_discount_from_the_original_price( $discount, $discounting_amount, $cart_item, $single, $coupon ) {
    
      if ($coupon->discount_type == 'percent' && $coupon->code == 'fifty') {
    
        $discount_percentage = $coupon->amount / 100;
        $item                = wc_get_product($cart_item['product_id']);
    
        if ($item) {
          if ( $item->is_type( 'simple' ) ) {
            $sale_price    = $item->sale_price;
            $regular_price = $item->regular_price;
            if ( ($sale_price && $regular_price) && ($sale_price !==  $regular_price) ) {
              $discount_from_regular_price = $regular_price * $discount_percentage; 
              $discount = $discounting_amount - ($discount_from_regular_price * $cart_item['quantity']); 
            }
    
          } elseif ( $item->is_type( 'variable' ) ) {
            $variable_product = new WC_Product_Variation( $cart_item["variation_id"] );
            $sale_price    = $variable_product->sale_price;
            $regular_price = $variable_product->regular_price;
            
            if ( ($sale_price && $regular_price) && ($sale_price !==  $regular_price) ) {
              $discount_from_regular_price = $regular_price * $discount_percentage;
              $discount = $discounting_amount - ($discount_from_regular_price * $cart_item['quantity']);
            }
    
          }
        }
    
      }
      return $discount;
    }