Thanks for reply I am very grateful KÄrlis Millers, dingo-d now my widget it looks how.
<?php
class ultimos_productos_widget_1 extends WP_Widget {
function __construct() {
parent::__construct(
'ultimos_productos_widget', __( 'ultimos_productos_widget_1', 'tutsplustextdomain' ),
array(
'classname' => 'ultimos_productos_widget_1',
'description' => __( 'A basic text widget to demo the Tutsplus series on creating your own widgets.', 'tutsplustextdomain' )
)
);
}
public function widget($args,$instance){
extract( $args );
echo $before_widget = '<div class="sidebar woocommerce">' ;
?>
<h3 class="widget-title"> <?php _e('Ultimate Products', 'pruebadesarrollo'); ?></h3>
<ul class="products">
<?php
$args = array(
'post_type' => 'product',
'posts_per_page' => 5,
'product_cat' => 'marble',
'orderby' => 'ASC',
/*'tax_query' => array(
array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => 'marble',
),
),*/
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>
<li class="product">
<a href="<?php echo get_permalink( $loop->post->ID ) ?>" title="<?php echo esc_attr($loop->post->post_title ? $loop->post->post_title : $loop->post->ID); ?>">
<?php woocommerce_show_product_sale_flash( $post, $product ); ?>
<?php if (has_post_thumbnail( $loop->post->ID )) echo get_the_post_thumbnail($loop->post->ID, 'shop_catalog'); else echo '<img src="'.woocommerce_placeholder_img_src().'" alt="Placeholder" width="300px" height="300px" />'; ?>
<h3><?php the_title(); ?></h3>
<span class="price"><?php echo $product->get_price_html(); ?></span>
</a>
<?php if(is_user_logged_in() ){ ?>
<?php woocommerce_template_loop_add_to_cart( $loop->post, $product ); ?>
<?php } ?>
</li>
<?php endwhile; ?>
<?php wp_reset_postdata() ?>
</ul><!--/.products-->
<?php
echo $after_widget='</div>';
}
public function update($new_instance, $old_instance){
// Función de guardado de opciones
}
public function form($instance){
// Formulario de opciones del Widget, que aparece cuando añadimos el Widget a una Sidebar
}
}
function myplugin_register_widgets() {
register_widget( 'ultimos_productos_widget_1' );
}
add_action( 'widgets_init', 'myplugin_register_widgets' );
?>
It was working before of update a to wordpress 4.3.
In wp_debug show me this message:
Notice: The called constructor method for WP_Widget is deprecated since version 4.3.0! Use
Internet research I found that I should change the next line.
$this->WP_Widget('ultimos_productos_widget', "ultimos 5 proyectos", $widget_ops);
for
parent::__construct('ultimos_productos_widget', "ultimos 5 proyectos", $widget_ops);
I dont know what happened?
Widget need register after you created it
Just put after your class:
Or in wordpress style:
See more at CODEX
Thanks for your comments,
I modified the code with the suggestions y this is my custom widget.
This a plugin and works perfectly.
Thanks.