0

I have used create_function in my theme below.

add_action( 'widgets_init', create_function( '', 'register_widget( "Woocommerce_Header_Cart" );' ) );

But for PHP 7.3.0, the create_function() is deprecated.

Any idea, how to fix my codes above on PHP 7.3.0.

Thanks for your help,

  • 2
    Possible duplicate of [PHP 7.2 Function create\_function() is deprecated](https://stackoverflow.com/questions/48161526/php-7-2-function-create-function-is-deprecated) – cabrerahector Jun 09 '19 at 22:10

2 Answers2

2

Try this code

add_action( 'widgets_init', 'custom_widget_func');

funcation custom_widget_func(){
    register_widget( "Woocommerce_Header_Cart" );
}
Vel
  • 9,027
  • 6
  • 34
  • 66
1

Replace

add_action( 'widgets_init', create_function( '', 'register_widget( "Woocommerce_Header_Cart" );' ) );

with this, using an anonymous function instead :

add_action( 'widgets_init', function() { return register_widget("Woocommerce_Header_Cart"); } );
mivk
  • 13,452
  • 5
  • 76
  • 69