Domanda

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)

È stato utile?

Soluzione 2

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>

Altri suggerimenti

you don't have to edit the order-details.php page the woocommerce_order_details_after_order_table action will achieve the same results.

add_action( 'woocommerce_order_details_after_order_table',
            'namespace\custom_field_display_cust_order_meta', 10, 1 );

function custom_field_display_cust_order_meta( $order ) {
  echo '<form [whatever]>';
  /* translators: whatever */
  echo '<p>' . sprintf( __( '<strong>Property 1:</strong> %1$s (%2$s)' ),                                                                                                                                  
                        '<input [whatever]>'
                        . get_post_meta( $order->get_order_number(),
                                         'property 1.1', true )
                        . '</input>',
                        '<input [whatever]>'
                        . get_post_meta( $order->get_order_number(),
                                         'property 1.2', true )
                        . '</input>' )
       . '</p>';
  echo '[whatever]';
  echo '</form>';
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a wordpress.stackexchange
scroll top