• Resolved allstarsft

    (@allstarsft)


    Hi everyone, (SRP is a custom MSRP code snippet that I managed to add the full set into functions.php — from Single Product page admin to Front view of the Single product)

    I had used Code snippets in the past for SRP(shifted those into functions.php in the Child theme) to be included in Cart/Checkout’s Order Review — that works but it did not work for Order Emails.

    So now I require to add Attribute (Warranty) in the same places.

    I think I can use the same coding for the Attribute (Warranty), but am not sure about the coding for the Order Emails part. (But I need to know in place of “SRP” – what is the term of Attribute(Warranty) — is it pa_warranty?)

    Below is the Cart page – Product details currently.

    Ideally the format of how these customised fields should be in the Order Review Table is as follows :

    Format as follows :
    Product name
    (#SKU)
    Attribute – Warranty
    *
    Quantity
    POS Item No

    *

    SRP

    *denotes Ideally with a line space here


    Currently I added SRP side — codings into functions.php — :

    /** SRP in Cart Table - Order Review **/
    add_filter( 'woocommerce_cart_item_name', 'add_srp_after_item_name', 99, 3 );
    function add_srp_after_item_name( $item_name, $cart_item, $cart_item_key ) {
    // The WC_Product object
    $product = $cart_item['data'];
    if (empty($product)) {
    return $item_name;
    }
    // Get the SRP
    $srp = $product->get_meta('_srp');
    // When SRP doesn't exist
    if (empty($srp)) {
    return $item_name;
    }
    // Display the SRP
    $item_name .='<br><p style="color:darkblue; font-weight:600;" class="srp-price">'.__( "SRP : " . get_woocommerce_currency_symbol() . number_format( round($srp, 2), 2 ) ." / piece.","woocommerce"). '</p>';
    return $item_name;
    }
    // number_format( round($srp, 2), 2 ) -- first rounded to two decimal, and displayed in 2 decimals.
    

    I am open to use the Woocommerce Templates to change / add this as well. (For both SRP and Attribute (Warranty) — would that be simpler than code into functions.php?

    Below is the Checkout page — Order Review table

    Thank you.

    Regards

    ALLSTARS-FT

    • This topic was modified 1 year, 1 month ago by allstarsft.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support Shameem R. a11n

    (@shameemreza)

    Hi @allstarsft

    If you want to use the same code for the Warranty attribute as you used for the SRP, you can replace _srp it with _pa_warranty . The _pa_ prefix is used for product attributes in WooCommerce.

    As for the Order Emails, you will need to override the WooCommerce email templates. You can do this by copying the template files from the WooCommerce plugin to your child theme and modifying them there. This is a bit more complex than adding code to functions.php, but it gives you more control over the layout and design of your emails.

    Further information can be found here: https://woocommerce.com/document/template-structure/#how-to-edit-files

    I hope this helps you to figure it out! Let us know if you have any other questions.

    Thread Starter allstarsft

    (@allstarsft)

    Thank you for your help. I’ve separately checked with my theme’s support, and I gotten the Code snippet for adding pa_warranty in.

    /** Attribute (Warranty) in Order Review **/
    
    add_filter( 'woocommerce_cart_item_name', 'add_warranty_after_item_name', 99, 3 );
    add_filter( 'woocommerce_order_item_name', 'add_warranty_after_item_name', 99, 3 );
    
    function add_warranty_after_item_name( $item_name, $cart_item, $cart_item_key ) {
    // The WC_Product object
    $product = $cart_item['data'];
    
    if (empty($product)) {
    return $item_name;
    }
    
    // Get the Warranty
    $warranty = $product->get_attribute( 'pa_warranty' );
    
    // When Warranty doesn't exist
    if (empty($warranty)) {
    return $item_name;
    }
    
    // Display the Warranty
    
    $item_name .='<br><p style="color:darkblue; font-weight:600;" class="warranty-attribute">'.__( "Warranty : " . $warranty ." ", "woocommerce"). '</p>';
    
    return $item_name;
    }

    I have added this into functions.php – child theme and it works.

    Also in terms of adding the same fields (SRP and PA_warranty) — into all Order Emails, could you give me more specifics on how that can be done? Which template files to edit and how?

    Thank you.

    • This reply was modified 1 year, 1 month ago by allstarsft.
    Plugin Support Shameem R. a11n

    (@shameemreza)

    Hi @allstarsft

    To add custom fields to your order emails, you can use WooCommerce’s action hooks. The woocommerce_email_order_meta action hook can be used to add data to all order emails.

    I found some resources that might help you grasp and reach your goal:

    I hope this helps! Please let us know how it goes or if you need further assistance.

    Thread Starter allstarsft

    (@allstarsft)

    @shameemreza — After reading through the 3 resources, I am still unable to comprehend — as those seems to only add custom data outside of the product details table.

    SRP, Shipping Class and Attribute – Warranty — these are fields that I require to be in each Product Detail — inside the Product Table. — Ideally should look the same as the Cart/Checkout pages. — ie, these 3 fields are before POS Item No (Product code plugin)

    Below screenshot is the Email Order details — which at present only contain the Product name, Qty, and POS Item No.

    In future, I would also wished to indicate Qty as a column and Unit Price as a column as well. — but those I think I will need to edit the Template separately.

    Thank you.

    • This reply was modified 1 year, 1 month ago by allstarsft.
    Plugin Support Shameem R. a11n

    (@shameemreza)

    Hi @allstarsft

    This is a bit of a complicated topic that needs some customization. Unfortunately, custom coding is not something we can assist with directly. For assistance with the customization or development with your site, we recommend that you seek help from the following:

    If you are comfortable with coding yourself and have questions, I would also recommend that you consider:

    I wish I could help more, but hopefully, this gets you going in the right direction to get the job done.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Adding SRP (custom plugin) field & Attribute (Warranty)’ is closed to new replies.