2016-09-12 1 views
1

Auf WooCommerce habe ich ein benutzerdefiniertes Feld days_manufacture für jedes Produkt mit unterschiedlichen (ganzzahligen) Werten.WooCommerce - Benutzerdefinierte Nachricht auf Thankyou und "Mein Konto" Bestellseiten

Auch habe ich diesen Code, der eine Nachricht auf Korbseite mit dem höchsten Wert von „Tage der Herstellung“ zeigt:

add_action('woocommerce_before_cart', 'days_of_manufacture'); 
function days_of_manufacture() { 
    $day_txt = ' ' . __('day', 'your_theme_domain_slug'); 
    $days_txt = ' ' . __('days', 'your_theme_domain_slug'); 
    $text = __('Your Order will be produced in: ', 'your_theme_domain_slug'); 
    $max_days = 0; 

    foreach(WC()->cart->get_cart() as $cart_item) 
     if($cart_item['days_manufacture'] > $max_days) 
      $max_days = $cart_item['days_manufacture']; 

    if($max_days != 0) { 
     if ($max_days == 1) 
      $days_txt = $day_txt; 

     $output = $text . $max_days . $days_txt; 
     echo "<div class='woocommerce-info'>$output</div>"; 
    } 
} 

Nun möchte ich diese Nachricht wie in thankyou Ansicht Reihenfolge anzuzeigen Seite und in My account > Orders > View order Seiten.

Ist es möglich?

Danke!

Antwort

1

Ja ist es ... aber da auf den entsprechenden Vorlagen keine Haken dafür vorhanden sind, müssen Sie 2 Vorlagen überschreiben (lesen Sie hierzu how to override woocommerce templates via a theme).

Schritt 1 - Die Funktion

function days_of_manufacture_order_view($order) { 
     $day_txt = ' ' . __('day', 'your_theme_domain_slug'); 
     $days_txt = ' ' . __('days', 'your_theme_domain_slug'); 
     $text = __('Your Order will be produced in: ', 'your_theme_domain_slug'); 
     $max_days = 0; 

     foreach($order->get_items() as $item) 
      if(get_post_meta($item['product_id'], 'days_manufacture', true) > $max_days) 
       $max_days = get_post_meta($item['product_id'], 'days_manufacture', true); 

     if($max_days != 0) { 
      if ($max_days == 1) 
       $days_txt = $day_txt; 

      $output = $text . $max_days . $days_txt; 
      echo "<div class='woocommerce-info' style='display:block !important;'>$output</div>"; // forcing display for some themes 
     } 
} 

Dieser Code geht in function.php Datei Ihres aktiven Kind Thema (oder Thema) oder auch in jeder Plugin-Datei.

Schritt 2 - Einfügen der Funktion in den Vorlagen

1) Die Vorlage Mein Konto Bestellung:

Diese Vorlage in befindet sich your_theme/woocommerce/myaccount/view-order.php

Hier ist ein Auszug aus diese Vorlage (mit der Funktion darin):

<?php 
/** 
* View Order 
* 
* Shows the details of a particular order on the account page. 
* 
* This template can be overridden by copying it to yourtheme/woocommerce/myaccount/view-order.php. 
* 
* HOWEVER, on occasion WooCommerce will need to update template files and you 
* (the theme developer) will need to copy the new files to your theme to 
* maintain compatibility. We try to do this as little as possible, but it does 
* happen. When this occurs the version of the template file will be bumped and 
* the readme will list any important changes. 
* 
* @see  https://docs.woocommerce.com/document/template-structure/ 
* @author WooThemes 
* @package WooCommerce/Templates 
* @version 2.6.0 
*/ 

if (! defined('ABSPATH')) { 
    exit; 
} 

?> 
<?php days_of_manufacture_order_view($order); // <== inserted Here ?> 
<p><?php 

// … … … 

2) Die Thankyou Ansicht Bestellvorlage:

Diese Vorlage in your_theme/woocommerce/checkout/thankyou.php

Hier befindet, ist ein Extrakt aus dieser Vorlage (mit der Funktion im Innern):

<?php 
/** 
* Thankyou page 
* 
* This template can be overridden by copying it to yourtheme/woocommerce/checkout/thankyou.php. 
* 
* HOWEVER, on occasion WooCommerce will need to update template files and you 
* (the theme developer) will need to copy the new files to your theme to 
* maintain compatibility. We try to do this as little as possible, but it does 
* happen. When this occurs the version of the template file will be bumped and 
* the readme will list any important changes. 
* 
* @see   https://docs.woocommerce.com/document/template-structure/ 
* @author  WooThemes 
* @package  WooCommerce/Templates 
* @version  2.2.0 
*/ 

if (! defined('ABSPATH')) { 
    exit; 
} 
if ($order) : ?> 

<?php days_of_manufacture_order_view($order); // inserted Here ?> 

    <?php if ($order->has_status('failed')) : ?> 

Dieser Code wurde getestet und funktioniert


Referenzen:

+0

Great !!!! Es funktioniert perfekt! Tksss !!!! –

Verwandte Themen