如何解决Woocommerce批量定价试图访问布尔类型值的数组偏移量
我正在使用 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();
}
对此的任何帮助将不胜感激。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。