我很难让数组 sort() 函数按预期工作,我也尝试过 ksort() 等。:::
这很好用
foreach( (array) $query as $post ) {
$VP = ( ( empty($PMD['vehicle_price'][0]) ) ? $VP = 'On Request' : $VP = $PMD['vehicle_price'][0] );
$vehicle_p[] = $VP;
}
$return = array_count_values($vehicle_p); //Key Value Unique ( count )
foreach($return as $value => $count) {
<li><span class="key">' . $value . '</span> (' . $count . ')</li>
}
Run Code Online (Sandbox Code Playgroud)
最终结果: 480000 (1)、80000 (2)、120400 (1)
我现在想对此进行排序,因此 80000 (2) 是列表中的第一个,然后是 120400 (1) 然后是 …
我有以下数组:::
WC_Cart Object (
[cart_contents] => Array (
[d6f5bb0bbc] => Array (
[product_id] => 14
[variation_id] => 325
[variation] => Array (
[Your Build] => Windows
)
[quantity] => 1
Run Code Online (Sandbox Code Playgroud)
如何更换(更新)[quantity] => 1说[quantity] => 3:::
任何援助将不胜感激 :::
更新>>>更多信息.使事情更清楚
下面是我想要访问的钩子(woocommerce_calculate_totals)来改变上面打印的数组中的值,这些值源于print_r($this);:::
我不知道如何创建我需要更新值的函数 add_action( 'woocommerce_calculate_totals', 'my_quantity' );
我曾经使用过数组和钩子,但这有点超出我的联盟:::
//允许插件在计算最终总数之前挂钩并更改总计
do_action('woocommerce_calculate_totals', $this);
/**
* Grand Total
*
* Based on discounted product prices, discounted tax, shipping cost + tax, and any discounts to be added after tax (e.g. …Run Code Online (Sandbox Code Playgroud)