1

I am creating a widget that handles order numbers. The basic structure is as follow:

// pretty generic widget functions
public function widget($args, $instance)
{
  $order_number = $instance['order_number'];
}
public function update($new_instance, $old_instance)
{
  $instance = $old_instance;
  $instance['order_number'] = strip_tags($new_instance['order_number']);
}


public function form($instance)
{
 if ($instance) {
    $order_number = esc_attr($instance['order_number']);
 }else {
    $order_number = '';
}

what I usually do is to ask the user for the order number. Like this:

<input name="<?php echo $this->get_field_name('order_number'); ?>" 
type="text" value="<?php echo $order_number; ?>" />

but now I want to have a function that generates order_number. So my function is

function order_generator($email){
     .....
     return $order_num;
}

I want order_num to be set for the value of order_number.

how can I do this?

Update #1

As requested by kaiserI try to explain this briefly.

First Case: I have a widget that prints the order number. This order number is entered by the user in an input field. As explained in the question, once the user enters an order_number it is saved in the instance and can be displayed later.

Now this is the question: I created a function called order_generator that dynamically creates the order number. The user doesn't have to enter the order_number. The function returns an integer named $order_num. I want to remove that input field which asked the user for order number and make the order_num value to order_number so I can display it.

0

1 Answer 1

1

As far I understood you want to assign the order number like $order_number = order_generator($email) inside the widget class.

Yes, you can do it that way unless the order_generator is in another class. If you order_generator function is in another class then first you need to instantiate the class then call the method like $instance_of_your_class->order_generator($email).

Hope that helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.