suchen

Heim  >  Fragen und Antworten  >  Hauptteil

Bestell-ID und Bestelldatum auf der WooCommerce-Downloadseite „Mein Konto“ anzeigen.

<p> <pre class="brush:php;toolbar:false;">add_filter( 'woocommerce_account_downloads_column_download-product', 'display_product_image_on_account_downloads' ); Funktion display_product_image_on_account_downloads( $download ) { // Ausrichtung nur auf Bestellseiten if ( ! is_wc_endpoint_url( 'downloads' ) ) return; if ( $download['product_id'] > 0 ) { $product = wc_get_product( $download['product_id'] ); $image = $product->get_image( array(324, 194) ); // Das Produktbild $order_id = $order->get_id(); // Die Bestell-ID if ( $download['product_url'] ) { echo $image . '<a href="' . esc_url( $download['product_url'] ) . '">' . esc_html( $download['product_name'] ) . '</a>'; echo '<p>' . esc_html( $order_id ) . '</p>'; echo '<p>' . esc_html( wc_format_datetime( $order->get_date_created() ) ) . '</p>'; } anders { echo $image . esc_html( $download['product_name'] ); } } }</pre> < p>
P粉330232096P粉330232096564 Tage vor490

Antworte allen(1)Ich werde antworten

  • P粉903969231

    P粉9039692312023-07-28 12:23:48

    我仔细检查了您的代码并发现其中有一些问题。所以您可以使用以下版本:

    add_filter( 'woocommerce_account_downloads_column_download-product', 'display_product_image_order_info_on_account_downloads', 10, 2 );
    function display_product_image_order_info_on_account_downloads( $download, $item ) {
        // Targeting view order pages only
        if ( ! is_wc_endpoint_url( 'downloads' ) ) return;
    
        if ( $download['product_id'] > 0 ) {
            $product    = wc_get_product( $download['product_id'] );
            $image      = $product->get_image( array( 324, 194 ) ); // The product image
            $order_id   = $item->get_order_id(); // Get the order ID from the $item object
            $order_date = $item->get_order()->get_date_created(); // Get the order date from the $item object
    
            if ( $download['product_url'] ) {
                echo $image . '<a href="' . esc_url( $download['product_url'] ) . '">' . esc_html( $download['product_name'] ) . '</a>';
                echo '<p>' . esc_html( $order_id ) . '</p>';
                echo '<p>' . esc_html( wc_format_datetime( $order_date ) ) . '</p>'; 
            } else {
                echo $image . esc_html( $download['product_name'] );
            }
        }
    }

    您可以将其添加到您的子主题的functions.php文件中。

    Antwort
    0
  • StornierenAntwort