wordpress - Woocommerce 在产品页面上显示销售日期
问题描述
我正在尝试在我的产品页面上显示销售日期范围从-> 到。我的代码适用于简单的产品,但对于变量我无法使用。我已经尝试了一段时间,但没有成功,我想我快到了,我想念一些简单的东西。我希望任何人都可以帮助我,因为我真的需要让这个工作,实现它会很棒。
$alreadyran = false;
function flux_sale_end_date_to_product_price( $price_html, $product ) {
$child = $product->get_children();
if($alreadyran){
return $price_html;
}
$alreadyran = true;
$sale_price = $product->get_sale_price();
$from = $product->get_date_on_sale_from();
if (
empty( $from ) ||
! $product->is_on_sale() ||
! is_single()
) {
return $price_html;
}
$output_content = '';
$date_format = apply_filters( 'flux_date_format', get_option( 'date_format' ) );
$sale_from_text = apply_filters( 'flux_sale_from_text', __( 'Promoção válida de', 'woocommerce-onsale-information' ) );
$sale_ends_on_text = apply_filters( 'flux_sale_ends_on_text', __( 'até', 'woocommerce-onsale-information' ) );
$wrapper_css_class = apply_filters( 'flux_wrapper_css_class', 'flux_wrapper' );
$sale_from_css_class = apply_filters( 'flux_sale_from_css_class', 'flux_sale_from_date' );
$sale_end_css_class = apply_filters( 'flux_sale_end_css_class', 'flux_sale_end_date' );
if ( $product->get_date_on_sale_from() ) {
$sale_from_date = date_i18n( $date_format, $product->get_date_on_sale_from()->getTimestamp() );
$sale_from_html = '<div class="' . $sale_from_css_class . '">' . $sale_from_text . ' ' . $sale_from_date . ' </div>';
$output_content .= $sale_from_html;
}
if ( $product->get_date_on_sale_to() ) {
$sale_end_date = date_i18n( $date_format, $product->get_date_on_sale_to()->getTimestamp() );
$sale_end_html = '<div class="' . $sale_end_css_class . '">' . $sale_ends_on_text . ' ' . $sale_end_date . ' </div>';
$output_content .= $sale_end_html;
}
$output = '<div class="' . $wrapper_css_class . '">' . $output_content . '</div>';
return apply_filters( 'flux_price_html', $price_html . $output );
}
add_filter( 'woocommerce_get_price_html', 'flux_sale_end_date_to_product_price', 100, 2 );
解决方案
推荐阅读
- android - 无法解决:firebase-storage-19.2.0
- javascript - Cloud Firestore 更新文档中的多个字段
- performance - Hive JDBC 连接没有通过 JMeter 发生
- c - 使用 for 循环制作 Loading... 动画
- elasticsearch - 是否可以通过过滤器在 Elastic Search 中添加数据?
- javascript - 如何组合两个数组中的值?
- javascript - React-Admin TextField 和 TextInput 不显示标签和 css
- python-3.x - 如何清除使用 Tkinter label().place() 函数显示的文本
- flutter - 用于空值的空检查运算符
- python - 如何在 Kivy 的 BoxLayout 中保持按钮比例