X
X
xdvz2020-06-13 13:25:56
WordPress
xdvz, 2020-06-13 13:25:56

How to enable / disable the discount in Woocomerce?

All products are uploaded to the site already at a discount (it is calculated according to the formula). You need to configure it so that it is activated through the checkbox in the product card. I understand what needs to be done through ACF, but I don’t know what backing to write.
How can this be implemented?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
WP Panda, 2020-06-22
@xdvz

More or less like this

$sp_fee            = 0;
      $discount_percent = .15;
      $discount_title   = __( 'Скидка 15% за самовывоз ' );

      foreach ( $cart_object->cart_contents as $key => $value ) {

        $quantiy  = $value[ 'quantity' ];
        $itmprice = $value[ 'data' ]->price;
        $sales    = get_post_meta( $value[ 'product_id' ], 'ex_discount', true );

        if ( empty( $sales ) && ! in_array( (int) $value[ 'product_id' ], $combo ) ) {
          $sp_fee += $itmprice * $quantiy * $discount_percent;
        }

      }

if ( ! empty( $discount_percent ) && ! empty( (int) $sp_fee ) ) {
      $woocommerce->cart->add_fee( $discount_title, - $sp_fee );
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question