• matt.bateman

    (@mattbateman-1)


    I was surprised that WooCommerce doesn’t support the entering of a backorder “in stock” date but I’ve fixed that by using a custom field where the client can enter a date which the items are expected back in stock.

    The storefront shows the custom field data when the item is out of stock. Something like “Out of Stock. New stock expected 12/06/2014”. That works fine, but the client wants that custom field data to display in the cart and the checkout. “Available on back order” is not enough.

    How can I drag data from the custom field in the product and display that on the cart, checkout and hopefully email receipt sent to the customer?

    https://www.ads-software.com/plugins/woocommerce/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter matt.bateman

    (@mattbateman-1)

    Quick update in case anyone has a hint. In the cart.php I’ve found the line which deals with the Backorder Notification. Here is the text as it appears:

    if ( $_product->backorders_require_notification() && $_product->is_on_backorder( $cart_item['quantity'] ) )
    echo '<p class="backorder_notification">' . __( 'Available on backorder', 'woocommerce' ) . '</p>';

    I’ve supplanted the last line for the following:

    echo 'Delivery after ', get_post_meta($post_id=get_queried_object_id(), $key=expected_stock_date, $single=true) ;

    Which doesn’t work. The intent is something along the lines of “Delivery after 13/06/2014”. The “Delivery After ” text displays but the array comes back as blank. I’ve tried a few variations but I can’t get the cart to pull the custom data from each product. I can use methods like $_product->get_title(), so I know there’s a way to do this. Also if I replace the post id property with just a vanilla post ID, the code works as expected. So I’m just after a method to grab the contents of that custom field. I’m so close but I’m still so far.

    Thread Starter matt.bateman

    (@mattbateman-1)

    echo 'Delivery after ', get_post_meta($_product->id, $key=expected_stock_date, $single=true) ;

    Works! Leaving this here in case somebody else needs it in future.

    Hi Matt

    I want to change the ‘available to back order’ text that displays for products on back order on the product pages to display my ‘Lead Time’ custom Field.

    I’ve done this:

    function backorder_text($available) {
    
    foreach($available as $i) {
    
    $available = str_replace('Available on backorder', '<div class="prod-code pc-leadtime">Lead Time: ', $available);
    
    }
    
    return $available;
    }
    add_filter('woocommerce_get_availability', 'backorder_text');

    But unfortunatley it only displays the custom fields title and not the content, which in this case is “Made for you in just eight weeks”

    Above you say you’ve added a custom field in your first post, could I please ask how?

    Look forward to hearing your thoughts ??

    KR

    James

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Display custom field data in Cart and Checkout’ is closed to new replies.