Answer the question
In order to leave comments, you need to log in
How to add the cost of each product in the Robokassa plugin?
It is necessary to add the names of all products in the order
. Here is the original part of the edited code:
public function generate_form($order_id){
global $woocommerce;
$order = new WC_Order( $order_id );
if ($this->testmode == 'yes'){
$action_adr = $this->testurl;
}
else{
$action_adr = $this->liveurl;
}
$out_summ = number_format($order->order_total, 2, '.', '');
$crc = $this->robokassa_merchant.':'.$out_summ.':'.$order_id.':'.$this->robokassa_key1;
$args = array(
// Merchant
'MrchLogin' => $this->robokassa_merchant,
'OutSum' => $out_summ,
'InvId' => $order_id,
'SignatureValue' => md5($crc),
'Culture' => 'ru',
);
public function generate_form($order_id){
global $woocommerce;
$order = new WC_Order( $order_id );
$items = $order->get_items();
foreach( $items as $item ) {
$item_total = $item['line_subtotal'];
$product_name = $item['name'];
}
if ($this->testmode == 'yes'){
$action_adr = $this->testurl;
}
else{
$action_adr = $this->liveurl;
}
$out_summ = number_format($order->order_total, 2, '.', '');
$out_summ2 = number_format($item_total, 2, '.', '');
$crc = $this->robokassa_merchant.':'.$out_summ.':'.$order_id.':'.$this->robokassa_key1;
$args = array(
// Merchant
'MrchLogin' => $this->robokassa_merchant,
'OutSum' => $out_summ,
'OutSum2' => $out_summ2,
'ProductName' => $product_name
'InvId' => $order_id,
'SignatureValue' => md5($crc),
'Culture' => 'ru',
);
Answer the question
In order to leave comments, you need to log in
Step 1. Get a good understanding of what this code does:
foreach( $items as $item ) {
$item_total = $item['line_subtotal'];
$product_name = $item['name'];
}
// Для каждого элемента массива $items
foreach( $items as $item ) {
// Устанавливаем значение переменной $item_total равной полю line_subtotal текущего элемента
$item_total = $item['line_subtotal'];
// Устанавливаем значение переменной $product_name равной полю name текущего элемента
$product_name = $item['name'];
}
$item_total = 0.0;
$product_names = [];
foreach ($items as $item)
{
$item_total += (float)$item['line_subtotal'];
$product_names[] = $item['name'];
}
$out_summ2 = number_format($item_total, 2, '.', '');
$args = [
'MrchLogin' => $this->robokassa_merchant,
'OutSum' => $out_summ,
'OutSum2' => $out_summ2,
'ProductName' => implode(', ', $product_names),
'InvId' => $order_id,
'SignatureValue' => md5($crc),
'Culture' => 'ru',
];
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question