1

I am creating woocommerce plugin and I have a custom order status "wc-shipped". I want to execute some plugin options for this custom order status only. Here is my code


add_action('text_sms_form_fields', 'sms_woocommerce_fields', 10, 1);
function sms_woocommerce_fields($textme_option, $wc_statuses_arr) { ?>
if( isset( $wc_statuses_arr['wc-shipped'] ) ) {  ?>
                <hr>
                <fieldset>
                    <label for="textme_order_shipped">
                        <input name="textme_order_shipped" type="checkbox"
                               id="textme_order_shipped" <?php if ($textme_option['textme_order_shipped'] == "1") {
                            echo 'checked';
                            
                        } ?>
                               value="1"/>
                        <span><?php esc_html_e('Send SMS when order status is shipped ', 'send_sms'); ?></span>
                    </label>
                </fieldset>

                <div class="textme_order_shipped_content <?php if ($textme_option['textme_order_shipped'] != '1') {
                    echo 'hidden';
                } ?>">
                    <table>
                        <tr>
                            <td></td>
                            
                                <td><textarea id="textme_order_shipped_sms_customer" name="textme_order_shipped_sms_customer"
                                          cols="80" rows="3"
                                          class="all-options"><?php if ($textme_option['textme_order_shipped_sms_customer']) {
                                        echo $textme_option['textme_order_shipped_sms_customer'];
                                    } ?></textarea>
                            </td>
                        </tr>
                    </table>
                </div>
                <?php } ?>

I want if "wc-shipped" status exist then show these plugin options but I am getting below error.

How to fix this ?

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
Hannah James
  • 540
  • 3
  • 14

1 Answers1

1

Your hooked function has 2 variables (arguments), so you need to declare those 2 variables replacing the first line of your code:

add_action( 'text_sms_form_fields', 'sms_woocommerce_fields', 10, 1 );

simply by:

add_action( 'text_sms_form_fields', 'sms_woocommerce_fields', 10, 2 );

This should solve this problem. See WordPress add_action()...

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
  • Sir, it's not working, but i tried $wc_statuses = wc_get_order_statuses(); foreach ($wc_statuses as $key => $value) { echo $value; } then i get this value: Pending paymentProcessingOn holdCompletedCancelledRefundedFailedShipped. with this value how can we add if shipped status exist ? regards – Hannah James Oct 26 '20 at 10:21
  • Thank you sir, this line works $wc_statuses = wc_get_order_statuses(); if( isset( $wc_statuses['wc-shipped'] ) ) { ?> Regards – Hannah James Oct 26 '20 at 10:25