I have code which prints text after the price when on sale and I am now getting an error using this code, which I did not get before. It says: "PHP Warning: date() expects parameter 2 to be integer" and it refers to this line:
$sales_price_date_to = date( "j.M.Y", $sales_price_to );
Any ideas on how to fix it?
add_filter( 'woocommerce_get_price_html', 'custom_price_html', 100, 2 );
function custom_price_html( $price, $product ){
global $post;
$sales_price_to = get_post_meta( $product->id, '_sale_price_dates_to', true );
$sales_price_date_to = date( "j.M.Y", $sales_price_to );
if ( is_single() ) {
if($product->is_type( 'simple' ) && $sales_price_to != "" ) {
$sales_price_date_to = date("j.m.Y", $sales_price_to);
return str_replace( '</ins>', ' </ins> <span class="notice-price">(on offer until '.$sales_price_date_to.')</span>', $price );
} else if ( $product->is_type( 'variable' ) ){
$handle = new WC_Product_Variable( $product->id);
$variations1 = $handle->get_children();
$content_variations = "";
$count_each_var = 0;
foreach ($variations1 as $value) {
$count_each_var++;
$single_variation = new WC_Product_Variation($value);
$var_id = $single_variation->variation_id;
$sales_price_to_variable = get_post_meta($var_id, '_sale_price_dates_to', true);
if( $sales_price_to_variable != '' ){
$sales_price_date_to = date("j.m.Y", $sales_price_to_variable);
if($count_each_var == 1) {
$class_val = 'class="active"';
} else {
$class_val = "";
}
$content_variations .= "<i data-id='". $var_id ."' data-order='".$count_each_var."' $class_val >".$sales_price_date_to."</i>";
} else {
$content_variations .= "";
}
}
if( $content_variations != ''){
return str_replace( '</ins>', ' </ins> <span class="notice-price">(on offer until '.$content_variations.')</span>', $price );
} else {
return $price;
}
} else {
return apply_filters( 'woocommerce_get_price', $price );
}
}
}
Been trying to fix it, but I can't.