最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Woocommerce frontend edit custom fields

programmeradmin1浏览0评论

i have add 4 custom fields in the checkout page (in functions.php )

Now i show the value in the Order page with

get_post_meta( $order->id, 'My Field', true )

I need that the customer can edit the Value on the order Page (front-end) if the order status is processing.

I dont know who can i make this.

I have try to use the acf Plugin (ACF Plugin)

for use this on the checkout page. But i found nothing and the support of acf dont anwser to this topic.

The next way was that i try to load the custom filed value as "default_value" of the acf input Plugin. But it dont work.

function my_acf_load_field( $field ) {

 //$acfstrasse = get_field('field_name', $post_id);
 $acfstrasse = get_post_meta( $order->id, 'Strasse', true );

 $field['default_value'] = $acfstrasse;
 return $field;

}
add_filter('acf/load_field/name=field_name', 'my_acf_load_field');

I hope you know a way that the customer can edit the value of the custom field on the order page (front-end)

Thanks !!

Sorry for my english. (German is my language)

i have add 4 custom fields in the checkout page (in functions.php )

Now i show the value in the Order page with

get_post_meta( $order->id, 'My Field', true )

I need that the customer can edit the Value on the order Page (front-end) if the order status is processing.

I dont know who can i make this.

I have try to use the acf Plugin (ACF Plugin)

for use this on the checkout page. But i found nothing and the support of acf dont anwser to this topic.

The next way was that i try to load the custom filed value as "default_value" of the acf input Plugin. But it dont work.

function my_acf_load_field( $field ) {

 //$acfstrasse = get_field('field_name', $post_id);
 $acfstrasse = get_post_meta( $order->id, 'Strasse', true );

 $field['default_value'] = $acfstrasse;
 return $field;

}
add_filter('acf/load_field/name=field_name', 'my_acf_load_field');

I hope you know a way that the customer can edit the value of the custom field on the order page (front-end)

Thanks !!

Sorry for my english. (German is my language)

Share Improve this question asked Dec 6, 2015 at 9:01 kreativcubekreativcube 111 silver badge5 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

I found a solution.

i have use this code on my order-details.php Page

 <?php
         global $post;

         $post = $order_id;

           if ( isset( $_POST['submit'] ) )
             {
                     echo 'Update nicht';
             } else  if ( ! empty( $_POST['frontstrasse'] ) ) {
            update_post_meta( $order_id, 'Strasse', sanitize_text_field( $_POST['frontstrasse'] ) );
            update_post_meta( $order_id, 'Haus-Nr', sanitize_text_field( $_POST['fronthausnr'] ) );


}
$istrasse = get_post_meta($order->id, 'Strasse', true );
$ihausnr = get_post_meta($order->id, 'Haus-Nr', true );

  ?>

 <form method="post" action="">
<label>Strasse</label><input type='text' name='frontstrasse' value='<?php echo $istrasse ?>' />
<label>Haus-Nr</label><input type='text' name='fronthausnr' value='<?php echo  $ihausnr ?>' />
<input type='submit' value='save' name='frontsubmit' />
 </form>
发布评论

评论列表(0)

  1. 暂无评论