如何解决覆盖插件函数.php
您好,我对插件做了一些更改,但更新后我必须每次更改代码。现在如何为functions.PHP 构建过滤器。这是我所做的更改。
它们只是一些可变的变化。我需要这些才能正确同步。
我希望有人能帮我构建这个:)
protected function get_order_items($order) {
$order_items = array();
$incl_tax = get_option('woocommerce_tax_display_cart') == 'incl';
foreach ($order->get_items() as $item) {
if ($incl_tax) {
$price = ($item['line_subtotal'] + $item['line_subtotal_tax']) / $item['qty'];
} else {
$price = $item['line_subtotal'] / $item['qty']; // WC3+ ($item->get_subtotal()/$item->get_quantity()),}
$product = $this->get_product_from_item($item);
$data = array(
'sku' => $product ? $product->get_sku() : '','name' => $item['name'],// WC3+ $item->get_name(),'quantity' => $item['qty'],// WC3+ $item->get_quantity(),'price' => $this->round_price($price),'tax_id' => Options::get('bf_tax_' . ($item['tax_class'] ?: 'standard')),// WC3+ $item->get_tax_class();
'account_id' => Options::get('bf_account_products'),);
$data = apply_filters('bf_wc_lq_connector_order_item_data',$data,$item,$product);
if (isset($item['variation_id'])) {
$data['text'] = $this->get_item_attribute_Meta($item);
}
if (Options::get('bf_display_product_excerpt')) {
$excerpt = get_the_excerpt($item['product_id']);
if ($excerpt) {
$data['text'] = isset($data['text']) ? $data['text'] . $excerpt : $excerpt;
}
}
array_push($order_items,$data);
}
return $order_items;
}
这里是变量的变化。 修改:
protected function get_order_items($order) {
$order_items = array();
$incl_tax = get_option('woocommerce_tax_display_cart') == 'incl';
foreach ($order->get_items() as $item) {
if ($incl_tax) {
$price = ($item['line_subtotal'] + $item['line_subtotal_tax']) / $item['qty'];
} else {
$price = $item['line_subtotal'] / $item['qty']; // WC3+ ($item->get_subtotal()/$item->get_quantity()),}
$product = $this->get_product_from_item($item);
$posname = $item->get_Meta("posname");
$pa_groesse = strtoupper($item->get_Meta("pa_groesse"));
$pa_farbe = ucfirst($item->get_Meta("pa_farbe"));
$nameneu = $posname . ' - ' . $pa_farbe .',' . $pa_groesse;
$oriname = $item['name'];
if ( empty($posname) ) $nameneu = $oriname;
$artnr = strtoupper($item->get_Meta("artnr"));
if ( empty($artnr) ) $artnr = $product ? $product->get_sku() : '';
$data = array(
'sku' => $artnr,'name' => $nameneu,$product);
if (array_key_exists('variation_id',$item)) {
$data['text'] = $this->get_item_attribute_Meta($item);
}
if (Options::get('bf_display_product_excerpt')) {
$excerpt = get_the_excerpt($item['product_id']);
if ($excerpt) {
$data['text'] = isset($data['text']) ? $data['text'] . $excerpt : $excerpt;
}
}
array_push($order_items,$data);
}
return $order_items;
}
解决方法
也许您可以按照以下代码更新 &data 参数:
add_filter('bf_wc_lq_connector_order_item_data',function( $data,$item,$product ) {
$posname = $item->get_meta('posname');
$pa_groesse = strtoupper($item->get_meta('pa_groesse'));
$pa_farbe = ucfirst($item->get_meta('pa_farbe'));
$nameneu = $posname . ' - ' . $pa_farbe . ',' . $pa_groesse;
$oriname = $item['name'];
if ( empty($posname) ) {
$nameneu = $oriname;
}
$artnr = strtoupper($item->get_meta('artnr'));
if ( empty($artnr) ) {
$artnr = $product ? $product->get_sku() : '';
}
$data['sku'] = $artnr;
$data['name'] = $nameneu;
return $data;
},10,2);
,
现在在路人的帮助下,我迈出了第一步。
另一个步骤是
我在同一个文件中有这个代码
if (isset($item['variation_id'])) {
$datenalt = $this->get_item_attribute_meta($item);
$daten1 = preg_replace('/<li><strong class="wc-item-meta-label">Rücken Logo:<\/strong>.*?<\/li>/s','',$datenalt); //Brustlogo
$daten2 = preg_replace('/<li><strong class="wc-item-meta-label">Brust Logo:<\/strong>.*?<\/li>/s',$daten1); //Brustlogo
$daten3 = preg_replace('/<li><strong class="wc-item-meta-label">Artikelnummer:<\/strong>.*?<\/li>/s',$daten2); //artnr
$daten4 = preg_replace('/<li><strong class="wc-item-meta-label">Name:<\/strong>.*?<\/li>/s',$daten3); //artnr
$datentext = preg_replace('/<li><strong class="wc-item-meta-label">Preis:<\/strong>.*?<\/li>/s',$daten4);//preis
$datenneu = '<i>Artikelnummer: '. $artnr . '</i></br>' . $datentext;
$data['text'] = $datenneu;
}
ori 是这个代码:
if (isset($item['variation_id'])) {
$data['text'] = $this->get_item_attribute_meta($item);
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。