Search code examples
csswordpresswoocommercehook-woocommerce

Assign 'DIV ID' a value. (WooCommerce)


New to this forum and also new to coding, so please bear with me since it’S probably a simple answer to my question!

I have the below code which pops up a window for user ratings at order confirmation. The pop up window comes up fine but the values are not being populated.

The values I need are: email, order number and date the order was placed (no time needed, just the date format in YYYY-MM-DD).

When I echo the values they are correct. Only the date for some reason is not being populated, that is my first issue.

If I hard code the values when assigning the Div Id values it works fine but it does not pull the data correctly on it’s own. i.e. user@email.com()

Any help would be appreciated.

Here is the code I found on the internet and have tried various combinations but failed!

add_action( ‘woocommerce_order_details_after_order_table’, ‘trusted_shops_thankyou’, 15, 1 );
function trusted_shops_thankyou( $order ) {

echo $order->get_billing_email();
echo $order->get_order_number();
echo $order->get_date_completed();

// I need to fill the following DIVs
echo ‘
    <div id=”ratingvalues” style=”display: none;”>
        <div id=”rating_ordermail”>echo $order->get_billing_email()</div>
        <div id=”rating_ordernumber”>echo $order->get_order_number()</div>
        <div id=”rating_orderdate”>echo $order->get_date_completed()</div>
    </div>
    ‘;
}

Solution

    1. First of all, your code contains the wrong single quotation marks (') and double quotation marks (")
    2. In your div you use some css, display: none;. This will hide the div
    3. WC_Order get_date_completed() method will gives a date if the order has been completed once, so if the shop manager change the status from "completed" to "processing", the $order->get_date_completed() will gives a date.

    So then you get:

    // Display in "Order received" and "Order view" pages (frontend)
    function trusted_shops_thankyou( $order ) {
        // Getters
        $order_billing_email = $order->get_billing_email();
        $order_number = $order->get_order_number();
        $order_date_completed = $order->get_date_completed();
    
        // I need to fill the following DIVs
        echo '
        <div id="ratingvalues">
            <div id="rating_ordermail">' . $order_billing_email . '</div>
            <div id="rating_ordernumber">' . $order_number . '</div>
            <div id="rating_orderdate">' . $order_date_completed . '</div>
        </div>';
    }
    add_action( 'woocommerce_order_details_after_order_table', 'trusted_shops_thankyou', 10, 1 );