It has been more than a week that I have been fighting with this issue and haven't got a fix around it. I'm trying to extend a class and overwrite some methods of it, so that I can display my own messages over there:
The parent class:
class Order {
public function details( $echo = true ) {
$cart = $this->get_cart();
$currency = $this->get_meta( 'mp_payment_info->currency', '' );
$cart = $this->get_meta( 'mp_cart_items' );
if ( ! $cart ) {
$cart = $this->get_meta( 'mp_cart_info' );
}
/**
* Filter the confirmation text
*
* @since 3.0
*
* @param string The current confirmation text.
* @param MP_Order The order object.
*/
$confirmation_text = apply_filters( 'mp_order/confirmation_text', '', $this );
$confirmation_text = apply_filters( 'mp_order/confirmation_text/' . $this->get_meta( 'mp_payment_info->gateway_plugin_name' ), $confirmation_text, $this );
$cart_contents = '';
ob_start();
?>
<?php if ( is_array( $cart ) ): ?>
<?php foreach ( $cart as $product_id => $items ): ?>
<?php foreach ( $items as $item ): ?>
<?php $product = new MP_Product( $product_id ); ?>
<div class="mp_cart_item" id="mp-cart-item-104">
<div class="mp_cart_item_content mp_cart_item_content-thumb"><img
src="<?php echo $product->image_url( false ) ?>"
width="75" height="75" style="max-height: 75px;">
</div>
<!-- end mp_cart_item_content -->
<div class="mp_cart_item_content mp_cart_item_content-title">
<h2 class="mp_cart_item_title">
<a href="<?php echo $item['url'] ?>"><?php echo $item['name'] ?></a>
</h2>
<?php
if ( $product->is_download() && mp_is_shop_page( 'order_status' ) ) {
echo '<a target="_blank" href="' . $product->download_url( get_query_var( 'mp_order_id' ), false ) . '">' . __( 'Download', 'mp' ) . '</a>';
}
?>
</div>
<!-- end mp_cart_item_content -->
<div class="mp_cart_item_content mp_cart_item_content-price"><!-- MP Product Price -->
<div class="mp_product_price" itemtype="http://schema.org/Offer" itemscope=""
itemprop="offers">
<span class="mp_product_price-normal"
itemprop="price"><?php echo mp_format_currency( '', $item['price'] ) ?></span>
</div>
<!-- end mp_product_price -->
</div>
<!-- end mp_cart_item_content -->
<div
class="mp_cart_item_content mp_cart_item_content-qty"><?php echo $item['quantity'] ?>
</div>
<!-- end mp_cart_item_content --></div><!-- end mp_cart_item -->
<?php endforeach; ?>
<?php endforeach; ?>
<?php else: ?>
<?php
$cart->display( array(
'echo' => true,
'view' => 'order-status',
'editable' => false,
) );
?>
<?php endif; ?>
<?php
$cart_contents = ob_get_clean();
$html = '
<!-- MP Single Order Details -->
<section id="mp-single-order-details" class="mp_orders">
<div class="mp_order_details">
<div class="mp_order">' .
$this->header( false ) .
'</div><!-- end mp_order -->' .
$confirmation_text . '
<div class="mp_order_cart">' .
$cart_contents . '
</div><!-- end mp_order_cart -->
<div class="mp_order_address">' .
$this->get_addresses() . '
</div><!-- end mp_order_address -->
</div><!-- end mp_order_details -->
</section><!-- end mp-single-order-details -->';
/**
* Filter the order details
*
* @since 3.0
*
* @param string $html The current details.
* @param MP_Order $this The current order object.
*/
$html = apply_filters( 'mp_order/details', $html, $this );
if ( $echo ) {
echo $html;
} else {
return $html;
}
}
}
My class extending this:
class My_Order extends Order {
public function details( $echo = true ) {
$cart = $this->get_cart();
$currency = $this->get_meta( 'mp_payment_info->currency', '' );
$cart = $this->get_meta( 'mp_cart_items' );
if ( ! $cart ) {
$cart = $this->get_meta( 'mp_cart_info' );
}
/**
* Filter the confirmation text
*
* @since 3.0
*
* @param string The current confirmation text.
* @param MP_Order The order object.
*/
$confirmation_text = apply_filters( 'mp_order/confirmation_text', '', $this );
$confirmation_text = apply_filters( 'mp_order/confirmation_text/' . $this->get_meta( 'mp_payment_info->gateway_plugin_name' ), $confirmation_text, $this );
$cart_contents = '';
ob_start();
?>
<?php if ( is_array( $cart ) ): ?>
<?php foreach ( $cart as $product_id => $items ): ?>
<?php foreach ( $items as $item ): ?>
<?php $product = new MP_Product( $product_id ); ?>
<div class="mp_cart_item" id="mp-cart-item-104">
<div class="mp_cart_item_content mp_cart_item_content-thumb"><img
src="<?php echo $product->image_url( false ) ?>"
width="75" height="75" style="max-height: 75px;">
</div>
<!-- end mp_cart_item_content -->
<div class="mp_cart_item_content mp_cart_item_content-title">
<h2 class="mp_cart_item_title">
<a href="<?php echo $item['url'] ?>"><?php echo $item['name'] ?></a>
</h2>
<?php
if ( $product->is_download() && mp_is_shop_page( 'order_status' ) ) {
echo '<a target="_blank" href="' . $product->download_url( get_query_var( 'mp_order_id' ), false ) . '">' . __( 'Download', 'mp' ) . '</a>';
}
?>
</div>
<!-- end mp_cart_item_content -->
<div class="mp_cart_item_content mp_cart_item_content-price"><!-- MP Product Price -->
<div class="mp_product_price" itemtype="http://schema.org/Offer" itemscope=""
itemprop="offers">
<span class="mp_product_price-normal"
itemprop="price"><?php echo mp_format_currency( '', $item['price'] ) ?></span>
</div>
<!-- end mp_product_price -->
</div>
<!-- end mp_cart_item_content -->
<div
class="mp_cart_item_content mp_cart_item_content-qty"><?php echo $item['quantity'] ?>
</div>
<!-- end mp_cart_item_content --></div><!-- end mp_cart_item -->
<?php endforeach; ?>
<?php endforeach; ?>
<?php else: ?>
<?php
$cart->display( array(
'echo' => true,
'view' => 'order-status',
'editable' => false,
) );
?>
<?php endif; ?>
<?php
$cart_contents = ob_get_clean();
$html = 'I JUST WANT TO REPLACE THIS';
/**
* Filter the order details
*
* @since 3.0
*
* @param string $html The current details.
* @param MP_Order $this The current order object.
*/
$html = apply_filters( 'mp_order/details', $html, $this );
if ( $echo ) {
echo $html;
} else {
return $html;
}
}
}
Where the only thing I want to override is this: $html = 'I JUST WANT TO REPLACE THIS';
I have also tried overriding other methods of this class as well, but none of them works.
Thanks
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire