php - Woocommerce 批量定价尝试访问 bool 类型值的数组偏移量
问题描述
我正在使用 Woocommerce 包括增值税和不包括增值税价格代码代码。
add_filter('woocommerce_get_price_html', 'display_prices_incl_and_excl_taxes', 100, 2 );
function display_prices_incl_and_excl_taxes( $price_html, $product ) {
global $woocommerce_loop;
// On single product pages only (and not on any product loop)
if( isset($woocommerce_loop['total']) && $woocommerce_loop['total'] == 0
&& isset($woocommerce_loop['total']) && empty($woocommerce_loop['name']) ) {
// For simple products and products variations
if( $product->is_type('simple') || $product->is_type('variation') ) {
// On sale products
if( $product->is_on_sale() ) {
$regular_price_incl_tax = wc_get_price_including_tax( $product, array( 'price' => $product->get_regular_price() ) );
$price_incl_tax_html = wc_format_sale_price( $regular_price_incl_tax, wc_get_price_including_tax( $product ) );
$regular_price_excl_tax = wc_get_price_excluding_tax( $product, array( 'price' => $product->get_regular_price() ) );
$price_excl_tax_html = wc_format_sale_price( $regular_price_excl_tax, wc_get_price_excluding_tax( $product ) );
}
// Not on sale
else {
$price_incl_tax_html = wc_price( wc_get_price_including_tax( $product ) );
$price_excl_tax_html = wc_price( wc_get_price_excluding_tax( $product ) );
}
}
// variable pproducts
elseif( $product->is_type('variable') ) {
$prices = $product->get_variation_prices( true );
if ( ! empty( $prices['price'] ) ) {
$act_keys = array_keys($prices['price']);
$reg_keys = array_keys($prices['regular_price']);
$min_price_incl_tax = wc_get_price_including_tax( wc_get_product(reset($act_keys)));
$max_price_incl_tax = wc_get_price_including_tax( wc_get_product(end($act_keys)));
$min_price_excl_tax = wc_get_price_excluding_tax( wc_get_product(reset($act_keys)));
$max_price_excl_tax = wc_get_price_excluding_tax( wc_get_product(end($act_keys)));
$min_reg_price_jncl_tax = wc_get_price_including_tax( wc_get_product(reset($reg_keys)));
$max_reg_price_incl_tax = wc_get_price_including_tax( wc_get_product(end($reg_keys)));
$min_reg_price_excl_tax = wc_get_price_excluding_tax( wc_get_product(reset($reg_keys)));
$max_reg_price_excl_tax = wc_get_price_excluding_tax( wc_get_product(end($reg_keys)));
if ( $min_price_excl_tax !== $max_price_excl_tax ) {
$price_incl_tax_html = wc_format_price_range( $min_price_incl_tax, $max_reg_price_incl_tax );
$price_excl_tax_html = wc_format_price_range( $min_price_excl_tax, $max_reg_price_excl_tax );
}
elseif ( $product->is_on_sale() && $min_reg_price_excl_tax === $max_reg_price_excl_tax ) {
$price_incl_tax_html = wc_format_sale_price( wc_price( $max_reg_price_incl_tax ), wc_price( $min_price_incl_tax ) );
$price_excl_tax_html = wc_format_sale_price( wc_price( $max_reg_price_excl_tax ), wc_price( $min_price_excl_tax ) );
}
else {
$price_incl_tax_html = wc_price( $min_price_incl_tax );
$price_excl_tax_html = wc_price( $min_price_excl_tax );
}
}
}
if ( isset($price_incl_tax_html) && isset($price_excl_tax_html) ) {
$price_html = '<bdi><span class="inc-vat-price">'. __("Incl VAT") . ' - </span>' . $price_incl_tax_html . ' <bdi><br>';
$price_html .= '<bdi><span class="ex-vat-price">'. __("Excl VAT") . ' - </span>' . $price_excl_tax_html . '<bdi><br>';
$price_html .= $product->get_price_suffix();
}
}
return $price_html;
}
我正在使用 WPlab 的 WooCommerce Bulk Pricing 插件。
但是我遇到了这个错误,无法理解问题出在哪里。它仅适用于简单的产品,而可变产品则为我提供了值错误的数组偏移量。
PHP 注意:尝试访问第 599 行 /var/www/web/wp-content/plugins/woocommerce-bulk-pricing/classes/wc_bulk_pricing.class.php 中 bool 类型值的数组偏移量 PHP 注意:尝试访问数组第 601 行 /var/www/web/wp-content/plugins/woocommerce-bulk-pricing/classes/wc_bulk_pricing.class.php 中 bool 类型的值的偏移量
function generate_discount_table( $post_id, $active_ruleset = null ) {
$product = wc_get_product( $post_id );
// Skip generating the table if disable_on_sale_products is enabled
if ( $product->is_on_sale() && get_option( 'wc_bulk_pricing_disable_on_sale_products', 0 ) == 1 ) {
return;
}
$html = '<div class="bulk_pricing_discounts_wrapper">';
// header
if ( isset( $active_ruleset['custom_header'] ) && $active_ruleset['custom_header'] != '' ) {
$custom_header = stripslashes( $active_ruleset['custom_header'] );
} else {
$custom_header = get_option( 'wc_bulk_pricing_default_header', __('wc_bulk_pricing') );
$custom_header = $custom_header ? '<b>'.$custom_header.'</b><br>' : '';
}
// apply filter wc_bulk_pricing_custom_header
$custom_header = apply_filters( 'wc_bulk_pricing_custom_header', $custom_header, $active_ruleset, $post_id );
if ( $custom_header ) $html .= $custom_header;
if ( ! isset( $active_ruleset['hide_discount_table'] ) || $active_ruleset['hide_discount_table'] == '0' ) {
ob_start();
$wbp_variation_display_mode = get_option( 'wc_bulk_pricing_variation_display_mode', 'show');
echo "<script type='text/javascript'>var wbp_variation_display_mode = '{$wbp_variation_display_mode}';</script>";
echo '<div class="bulk_pricing_discounts" id="wpl_bp_wrap">';
woocommerce_bulk_pricing_shortcode::showHtmlTable( $active_ruleset['rules'], $post_id );
echo '</div>';
woocommerce_bulk_pricing_shortcode::showInlineJS( $active_ruleset['id'], $post_id );
$html .= ob_get_clean();
}
对此的任何帮助将不胜感激。
解决方案
推荐阅读
- angular - 按查询参数过滤的 json 服务器数组
- algorithm - 为什么在这种未定义的情况下我的 Dijkstra 算法的实现会失败?
- batch-file - 我正在制作一个 bat 文件,以便用另一个文件打开我将如何获取该文件?
- javascript - 循环遍历对象数组时,如何将对象值推送到新数组中?
- pandas - 仅在满足特定条件后如何将标题行添加到 df.to_csv 输出文件
- c - 使用 c 中只有 1 个条目的递归计算 1 个数组的总和
- javascript - Discord.js Reaction 打印格式问题
- javascript - 带有签名的 4 字节 int 的 protobuf 消息前缀
- vim - 如何让 Vimwiki 显示括号而不生成链接
- expo - 有没有博览会专业人士可以告诉我我做错了什么?(世博会)