Woocmmerce change product price and add text of discount received

I would like to create Woocommerce cart discount on the cart page, if there is more than 1 item in the cart give 50% discount on the cheapest product in the cart.

i.e.
2 items in cart:

  1. ProductA – 100$
  2. ProductB – 200$

Desired result in Cart:

  1. ProductA – 50$ (-50%)
  2. ProductB – 200$

Another scenario:

  1. ProductA – 100$
  2. ProductB – 200$
  3. ProductC – 300$
  4. ProductD – 400$

Desired result in Cart:

  1. ProductA – 50$ (-50%)
  2. ProductB – 100$ (-50%)
  3. ProductC – 300$
  4. ProductD – 400$

etc… etc…

I have already hooked to the cart and managed to change the prices accordingly but only for the first item.

How can I make this recursive and how can I add that (-50%) to the item that received that discount?

Here is the code I have:

function pozitive_recalculate_price( $  cart_object ) {      if ( is_admin() && ! defined( 'DOING_AJAX' ) ) {         return ;     }      $  products_prices_array = array();     $  cart_count = WC()->cart->get_cart_contents_count();     $  cart_object = $  cart_object->get_cart();      if( 0 < $  cart_count ) {         foreach ( $  cart_object as $  hash => $  value ) {             $  products_prices_array[$  hash] = $  value['line_subtotal'];         }         if( 0 == count( $  products_prices_array ) % 2 ) { // If even number of products, meaning 50% on 2nd product             $  minimum_price_array = array_keys( $  products_prices_array, min( $  products_prices_array ) );             $  cart_object[ $  minimum_price_array[0] ]['data']->set_price( $  cart_object[ $  minimum_price_array[0] ]['data']->get_price() / 2 );         }     } } add_action( 'woocommerce_before_calculate_totals', 'pozitive_recalculate_price' ); 

Thanks!

How Do I Make My Comment Reply Button Made with Element Work to Open Comment Reply Form Onclick

Please. I need your help to make it happen because I have just lost my hope to see this working. Here’s the screenshot of the code he uses on his blog. (Once he clicks over reply button made with span element, it opens a reply form on click that is just below that reply button and it closes the reply form on another click).

I made the span code with help of Sally CJ but to be honest, it is not working probably because it requires a script and custom reply form that opens on click over that span element.

Here’s the span element reply button I am using: enter image description here

And, I feel I need a script and custom reply form that opens when someone clicks over this reply button made with span element. I actually need a custom reply form for this reply button, probably a script if needed.

current_user_can capabilities in the admin not working as expected

I’m trying to block admin dashboard access using wp_redirect().

But the results of using current_user_can('edit_post') are unexpected.

See my complete function below…

/**  * user constructor method.  */ public function __construct() {      // block admin dashboard access     add_action( 'admin_init', array( $  this , 'block_admin_access' ) );  }  /**  * block admin dashboard access to users who cant edit posts  */ public function block_admin_access () {      // if users cannot edit posts     if( ! current_user_can('edit_post') ) {          // redirect user to home page         wp_redirect( get_home_url() );      }  } 

When I am logged in as an administrator user, this code above blocks me from the dashboard. Administrators can definately edit posts, so why does this code above redirect me away from the dashboard?

When I am using current_user_can('edit_post') on the front end, the behaviour is normal.

Does anyone know why this could be?

WordPress database error only while loading page for 1st time

I have this error when i open the page…but once i select the city from dropdown list,the error doesn’t exist. Error is like this: WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ” at line 1] SELECT * FROM wp_city_details WHERE id=

I have city dropdown list like this:

            <?php                         $  i = 1;                         $  cities = all_cities();                         foreach ($  cities as $  city){                             $  value = $  i . " " . $  city;             ?>                             <option              <?php                             if (isset($  _POST["city"])){                                 if ($  _POST["city"] == $  value){                                     ?> selected="true" <?php                                 };                             }             ?>                             value="<?php echo $  value; ?>"><?php echo $  city;?></option>             <?php                             $  i++;                         }             ?>                 </select> 

SOLD (Domain with DA45 PA42) Strong Backlinks

View attachment 236968
Da45 Pa42 Tf14 Cf24
External Backlinks: 137,942
Referring Domains: 492
EDU Backlinks: 1,310
EDU Domains: 12
GOV Backlinks: 31
GOV Domains: 1
Namebright, 10/2019
Backlink:

https://www.goodreads.com/user/show/22709882-sassy http://editora.globo.com/especiais/crescer_cuca_bacana/entrevista.asp?cod=4 http://tingtong.s13.xrea.com/cgi-bin/bbss/bbss.cgi https://www.goodreads.com/sassygirlbooks...
Code (markup):

SOLD (Domain with DA45 PA42) Strong Backlinks

1activist.com (Domain Name)

1activist.com
Registered : Godaddy.com
Price : $ 100 USD
Payment Method : Paypal
————————————————————-
How To Buy This Domain Through DigitalPoint Forum

1. You must have an account at digitalpoint forum, if you don't have yet, just create one, it's free.
Register -> https://www.digitalpoint.com/register/
2. click "domain info : 1activist.com (Beta)" at above this page, or you can just go to this link ->…

1activist.com (Domain Name)