php - Replace a value in object array

955

I have the following array

293

Answer

Solution:

This is what you wanted?

$wc_cart->cart_contents['d6f5bb0bbc']['quantity'] = 3;

A few examples of accessing arrays and objects:

$object->some_property
$object->{'complex'.'property'.'name'.(2*3)}
$array[12]
$array['hello']
$array[ $array_index*10 ]

Learn more about arrays and objects at:

778

Answer

Solution:

There are actions and filters in WordPress, they are different:

http://codex.wordpress.org/Function_Reference/add_action http://codex.wordpress.org/Function_Reference/add_filter

In WooCommerce there are two very similarly named action/filter:

  • woocommerce_calculate_totals action
  • woocommerce_calculated_total filter

woocommerce_calculate_totals actions are called with the cart object, so what you should do (and hopefully should work) is:

add_action( 'woocommerce_calculate_totals', 'my_quantity' );

function my_quantity( $wc_cart ){
  $wc_cart->cart_contents['d6f5bb0bbc']['quantity'] = 3;
}
160

Answer

Solution:

First getcart_contents out of the object, then work your way through the arrays:

$wc_cart->cart_contents['d6f5bb0bbc']['quantity'] = 3;

People are also looking for solutions to the problem: some pointers on a php mysql connection

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.