Вечер добрый! У меня есть форма ФИО, телефон, адрес, корзина с товаром (артикул и количество) и т.д. Нужно чтобы получилось domain.ru/index.php?user=ФИО&phone=телефон&address=адрес&articles[0]=артикул&quantities[0]=кол-во&articles[1]=артикул&quantities[1]=кол-во Добавлено спустя 1 минуту 45 секунд: корзина с товаром находиться вне формы подгружена woocommerce
Код (PHP): <form method="get" action="domain.ru/index.php"> <input type="text" name="user"> <input type="text" name="phone"> <input type="text" name="address"> <input type="text" name="articles[0]"> <input type="text" name="quantities[0]"> <input type="text" name="articles[1]"> <input type="text" name="quantities[1]"> <input type="submit" name="submit" value="Отправить"> </form>
Код (PHP): <input type="text" name="articles[0]"> <input type="text" name="quantities[0]"> <input type="text" name="articles[1]"> <input type="text" name="quantities[1]"> Как вот эти параметры взять из таблицы?
Что значит взять? Они доступны там где формируются. Они же как-то в таблице появляются, ты же хочешь добавить ещё один формат отображения этих данных. Там где-то должен быть по идее цикл, в него и добавь ещё форму или данные добавь в массив, а потом сформируй форму.
Вот может кому пригодиться. Код (Text): <br/><label for="account_first_name"><?php _e( 'Имя:', 'woocommerce' ); ?> <span class="required">*</span></label> <input type="text" class="form-row-wide" name="family" id="billing_first_name" value="<?php echo esc_attr($checkout->get_value( 'billing_first_name' )) ?>" </br> Помогите написать в php из такого: Код (PHP): <?php foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { $_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key ); if ( $_product && $_product->exists() && $cart_item['quantity'] > 0 && apply_filters( 'woocommerce_checkout_cart_item_visible', true, $cart_item, $cart_item_key ) ) { ?> <tr class="<?php echo esc_attr( apply_filters( 'woocommerce_cart_item_class', 'cart_item', $cart_item, $cart_item_key ) ); ?>"> <td class="product-name"> <?php echo apply_filters( 'woocommerce_cart_item_name', $_product->get_sku(), $cart_item, $cart_item_key ) . ' '; ?> <?php echo apply_filters( 'woocommerce_checkout_cart_item_quantity', ' <strong class="product-quantity">' . sprintf( $cart_item['quantity'] ) . '</strong>', $cart_item, $cart_item_key ); ?> <?php echo WC()->cart->get_item_data( $cart_item ); ?> </td> <?php } } ?> в такое Код (PHP): $myi=0; reset($myitems); while ($mym=current($myitems)) { $url.="&articles[".$myi."]=".$mym["id"]."&quantities[".$myi."]=".$mym["quantity"]; $myi++; next($myitems); }; Добавлено спустя 35 минут 49 секунд: в итоге должно получится articles[0]=артикул&quantities[0]=кол-во&articles[1]=артикул&quantities[1]=кол-во
Подскажите где ошибка? Вот сделал так Код (PHP): <? php <tr class="<? php echo esc_attr( apply_filters( 'woocommerce_cart_item_class', 'cart_item', $cart_item, $cart_item_key ) ); ?>"> <class="product-name"> <?php $myi=0; reset ($cart_item); while ($mym=current($cart_item)){ $myurl="&articles[".$myi."]=".$_product->get_sku()."&quantites[".$myi."]=". $cart_item['quantity']; $myi++; next ($cart_item); }; ?> <div><?php echo $myurl; ?> </div> ?> Ответ выдает вот такой &articles[0]=foort&quantites[0]=2 &articles[0]=foort2&quantites[0]=1 нужно чтобы получилось &articles[0]=foort&quantites[0]=2 &articles[1]=foort2&quantites[1]=1
странно, зачем там reset(), current(), next()? Может foreach использовать вместо while, там есть $key или используй так же $myi
Чет у меня не получается Добавлено спустя 26 минут 13 секунд: foreach когда делаю у меня получается вот так: &articles[0]=foort&quantites[0]=2&articles[1]=foort&quantites[1]=2...&articles[9]=foort&quantites[9]=2&articles[0]=foort2&quantites[0]=1...&articles[1]=foort2&quantites[9]=1 я все просмотрел, в каждой $cart_item 9 параметров $key и по ним едет цикл, когда переходит на другой товар цикл начинается сначала. Направьте на путь истинный уже все прочитал, ну или почти все может что не нашел((((
из таблицы товаров мне нужно отправлять два параметра: Артикул и количество пример: Товар 1: &articles[0]=foort&quantites[0]=2 Товар 2: &articles[1]=foort2&quantites[1]=1 и т.д. где foort это $_product->get_sku(), а 2 это $cart_item['quantity']
Я примерно собрал Код (PHP): <?php foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { $_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key ); if ( $_product && $_product->exists() && $cart_item['quantity'] > 0 && apply_filters( 'woocommerce_checkout_cart_item_visible', true, $cart_item, $cart_item_key ) ) { ?> <p class="<?php echo esc_attr( apply_filters( 'woocommerce_cart_item_class', 'cart_item', $cart_item, $cart_item_key ) ); ?>"> <p class="product-name"> <?php $myi=0; foreach ($cart_item as $key){ $myurl.="&articles[".$myi."]=".$_product->get_sku()."&quantites[".$myi."]=". $cart_item['quantity']; $myi++; next ($cart_item); $arr= array ($cart_item); $ar= array ($_product); }; ?> <div><?php echo $myurl; ?> </div> <div><?php echo "*******************"; ?></div> <div> <?php echo print_r($arr); ?></div> <div> <?php echo "//////////////////"; ?></div> <div> <?php echo print_r($ar); ?> </div> </p> </p> <?php } } ?> Вот так он выводит: &articles[0]=foort&quantites[0]=1&articles[1]=foort&quantites[1]=1 &articles[2]=foort&quantites[2]=1&articles[3]=foort&quantites[3]=1 &articles[4]=foort&quantites[4]=1&articles[5]=foort&quantites[5]=1 &articles[6]=foort&quantites[6]=1&articles[7]=foort&quantites[7]=1 &articles[8]=foort&quantites[8]=1&articles[9]=foort&quantites[9]=1 ******************* Array ( [0] => Array ( [product_id] => 565 [variation_id] => 0 [variation] => Array ( ) [quantity] => 1 [line_total] => 750 [line_tax] => 0 [line_subtotal] => 750 [line_subtotal_tax] => 0 [line_tax_data] => Array ( [total] => Array ( ) [subtotal] => Array ( ) ) [data] => WC_Product_Simple Object ( [id] => 565 [post] => WP_Post Object ( [ID] => 565 [post_author] => 16 [post_date] => 2013-12-01 15:49:59 [post_date_gmt] => 2013-12-01 11:49:59 [post_content] => Омега. [post_title] => Масло оливковое Олеастрон 2 [post_excerpt] => Характеристики: [post_status] => publish [comment_status] => open [ping_status] => closed [post_password] => [post_name] => maslo-olivkovoe-oleastron-2 [to_ping] => [pinged] => [post_modified] => 2016-03-23 22:29:40 [post_modified_gmt] => 2016-03-23 18:29:40 [post_content_filtered] => [post_parent] => 0 [guid] => http:// [menu_order] => 0 [post_type] => product [post_mime_type] => [comment_count] => 0 [filter] => raw ) [product_type] => simple [shipping_classrotected] => [shipping_class_idrotected] => 0 [total_stock] => [supportsrotected] => Array ( [0] => ajax_add_to_cart ) [price] => 750 [manage_stock] => no [stock_status] => instock [tax_status] => taxable [virtual] => no [sku] => foort ) ) ) 1 ////////////////// Array ( [0] => WC_Product_Simple Object ( [id] => 565 [post] => WP_Post Object ( [ID] => 565 [post_author] => 16 [post_date] => 2013-12-01 15:49:59 [post_date_gmt] => 2013-12-01 11:49:59 [post_content] => Омега. [post_title] => Масло оливковое Олеастрон 2 [post_excerpt] => Характеристики: [post_status] => publish [comment_status] => open [ping_status] => closed [post_password] => [post_name] => maslo-olivkovoe-oleastron-2 [to_ping] => [pinged] => [post_modified] => 2016-03-23 22:29:40 [post_modified_gmt] => 2016-03-23 18:29:40 [post_content_filtered] => [post_parent] => 0 [guid] => http:// [menu_order] => 0 [post_type] => product [post_mime_type] => [comment_count] => 0 [filter] => raw ) [product_type] => simple [shipping_classrotected] => [shipping_class_idrotected] => 0 [total_stock] => [supportsrotected] => Array ( [0] => ajax_add_to_cart ) [price] => 750 [manage_stock] => no [stock_status] => instock [tax_status] => taxable [virtual] => no [sku] => foort ) ) 1 &articles[0]=foort&quantites[0]=1&articles[1]=foort&quantites[1]=1 &articles[2]=foort&quantites[2]=1&articles[3]=foort&quantites[3]=1 &articles[4]=foort&quantites[4]=1&articles[5]=foort&quantites[5]=1 &articles[6]=foort&quantites[6]=1&articles[7]=foort&quantites[7]=1 &articles[8]=foort&quantites[8]=1&articles[9]=foort&quantites[9]=1 &articles[0]=foort2&quantites[0]=2&articles[1]=foort2&quantites[1]=2 &articles[2]=foort2&quantites[2]=2&articles[3]=foort2&quantites[3]=2 &articles[4]=foort2&quantites[4]=2&articles[5]=foort2&quantites[5]=2 &articles[6]=foort2&quantites[6]=2&articles[7]=foort2&quantites[7]=2 &articles[8]=foort2&quantites[8]=2&articles[9]=foort2&quantites[9]=2 ******************* Array ( [0] => Array ( [product_id] => 564 [variation_id] => 0 [variation] => Array ( ) [quantity] => 2 [line_total] => 2400 [line_tax] => 0 [line_subtotal] => 2400 [line_subtotal_tax] => 0 [line_tax_data] => Array ( [total] => Array ( ) [subtotal] => Array ( ) ) [data] => WC_Product_Simple Object ( [id] => 564 [post] => WP_Post Object ( [ID] => 564 [post_author] => 16 [post_date] => 2013-12-01 15:49:39 [post_date_gmt] => 2013-12-01 11:49:39 [post_content] => Разнообразие [post_title] => Масло оливковое Армония 2 [post_excerpt] => Характеристики: [post_status] => publish [comment_status] => open [ping_status] => closed [post_password] => [post_name] => maslo-olivkovoe-armoniya-2-2 [to_ping] => [pinged] => [post_modified] => 2016-04-05 06:57:39 [post_modified_gmt] => 2016-04-05 02:57:39 [post_content_filtered] => [post_parent] => 0 [guid] => http:// [menu_order] => 0 [post_type] => product [post_mime_type] => [comment_count] => 0 [filter] => raw ) [product_type] => simple [shipping_classrotected] => [shipping_class_idrotected] => 0 [total_stock] => [supportsrotected] => Array ( [0] => ajax_add_to_cart ) [price] => 1200 [manage_stock] => no [stock_status] => instock [tax_status] => taxable [virtual] => no [sku] => foort2 ) ) ) 1 ////////////////// Array ( [0] => WC_Product_Simple Object ( [id] => 564 [post] => WP_Post Object ( [ID] => 564 [post_author] => 16 [post_date] => 2013-12-01 15:49:39 [post_date_gmt] => 2013-12-01 11:49:39 [post_content] => Разнообразие [post_title] => Масло оливковое Армония 2 [post_excerpt] => Характеристики: [post_status] => publish [comment_status] => open [ping_status] => closed [post_password] => [post_name] => maslo-olivkovoe-armoniya-2-2 [to_ping] => [pinged] => [post_modified] => 2016-04-05 06:57:39 [post_modified_gmt] => 2016-04-05 02:57:39 [post_content_filtered] => [post_parent] => 0 [guid] => http:// [menu_order] => 0 [post_type] => product [post_mime_type] => [comment_count] => 0 [filter] => raw ) [product_type] => simple [shipping_classrotected] => [shipping_class_idrotected] => 0 [total_stock] => [supportsrotected] => Array ( [0] => ajax_add_to_cart ) [price] => 1200 [manage_stock] => no [stock_status] => instock [tax_status] => taxable [virtual] => no [sku] => foort2 ) ) 1