Horje
I need to append a text string to the order title when an order is placed in Woocommerce - Wordpress Solution
[Solved] - I need to append a text string to the order title when an order is placed in Woocommerce - Wordpress Solution
Try following codes
I need to append a text string to the order title when an order is placed in Woocommerce. In order to send extra order data to our accounting software (Sage), I am using a plugin; Woosage as the bridge. Woosage requires this extra data to be appended to the title of the product. I suspect I need to hook into the woocommerce_checkout_create_order. Attached is what I am trying to achieve (apparently this site doesn't include my attachments).

Solution - 1

Can you please explain what extra info you want to add?


Solution - 2

use el gancho de woocommerce para cuando se realiza el pedido y allí realiza la modificación que necesita


Solution - 3

Hello Keith, This code will do the trick (tested and works) The result : https://prnt.sc/yom2hx


function ProWPsite_output_elDigital_field()
{
    global $product;
    
   /* You can enable this in a custom product only (if you want to track a product campaign directly) */
    /*
    if ($product->get_id() !== 282) {
        return;
    }
    */
    
?>
<div class="ProWPsite-elDigital-field">
    <input type="hidden" id="ProWPsite-elDigital" name="ProWPsite-elDigital" value="." maxlength="20">
</div>
<?php
}
add_action('woocommerce_before_add_to_cart_button', 'ProWPsite_output_elDigital_field', 10);


function ProWPsite_add_elDigital_text_to_cart_item($cart_item_data, $product_id, $variation_id)
{
    $elDigital_text = filter_input(INPUT_POST, 'ProWPsite-elDigital');
    if (empty($elDigital_text)) {
        return $cart_item_data;
    }
    $cart_item_data['ProWPsite-elDigital'] = $elDigital_text;
    return $cart_item_data;
}
add_filter('woocommerce_add_cart_item_data', 'ProWPsite_add_elDigital_text_to_cart_item', 10, 3);


function ProWPsite_add_elDigital_text_to_order_items($item, $cart_item_key, $values, $order)
 {
        /* Change your custom text */
         $your_custom_text = 'Append this text';

    if (empty($values['ProWPsite-elDigital'])) {
        return;
    }
    $item->add_meta_data(' ', $your_custom_text);
}
add_action('woocommerce_checkout_create_order_line_item', 'ProWPsite_add_elDigital_text_to_order_items', 10, 4);
Regards


Solution - 4

If you want to append text to "Product" title, then use this filter:


add_filter( 'woocommerce_order_item_name', 'append_string_order_item_name', 10, 1 );
function append_string_order_item_name( $itemname ) {
    $new_itemname = 'mytextString' .$itemname;
    return $new_itemname;
}
However, if you are looking to edit the Order title (and not the product title), then you can use this filter:

add_filter( 'woocommerce_order_number', 'append_string_order_number' );

function append_string_order_number( $order_id ) {
    $prefix = 'mytextString';
    $new_order_id = $prefix . $order_id;
    return $new_order_id;
}
Does this solve your problem?


Solution - 5

you will use some static or dynamic text, it requires that in the database it be saved with the name you need?


Solution - 6

You must added the input field and send it's value to append it to the order title

Date: 2022-10-21 04:51:03
Category: Wordpress
More for You