• Resolved arndofiore80

    (@arndofiore80)


    hi, I tried to insert the quantity of stock of the product into the customized pads, but I couldn’t.
    I did some tests using the fortnite sniper on github but this didn’t bring me to the conclusion.

    $stock = get_post_meta( $post->ID, '_stock', true );
    
    add_filter( "puiw_get_default_dynamic_params", function ($stock, $order){
    	$stock["stock-quantity"] = '$stock()';
    	return $stock;
    }, 10, 2);

    Please help me, my knowledge is the number of products

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Author Amirhossein Hosseinpour

    (@amirhpcom)

    Hi, hope you are doing well.
    Please note that you are using wrong PHP syntax:
    $stock["stock-quantity"] = '$stock()';

    and if you need to hook into each item of order, you should use “puiw_printinvoice_create_html_item_row_metas” which syntax could be found on https://github.com/peprodev/ultimate-invoice/blob/master/include/admin/class-print.php#L693 .

    Thread Starter arndofiore80

    (@arndofiore80)

    add_filter( "puiw_get_default_dynamic_params", function ($stock, $optm){
    	$stock["stock-quantity"] = '';
    	return $stock;
    }, 10, 2);

    it should be so ?

    I’m not programming expert, I’m trying to be able to import the remaining stock quantity of an order into the order template of my site, could you help me to write the right code please?

    Plugin Author Pepro Dev. Group

    (@peprodev)

    Hi,

    You should first make a custom template using the guidelines given here:
    https://github.com/peprodev/ultimate-invoice/wiki/Add-Customized-External-Template-to-Ultimate-Invoice

    Then you need to add a custom macro to use in each order line item, something like the below snippet, and place it in the template you’ve created. (files with the “.row” suffix in the name).

    
    add_filter( "puiw_printinvoice_create_html_item_row_metas", "my_custom_lineitems_macros", 10, 5);
    // add the macro: { { { remaining-qty } } }
    function my_custom_lineitems_macros ($macros, $item_id, $item, $product_id, $order){
    	$product = $item->get_product();
    	$current_qty = $product->get_stock_quantity();
    	$bought_qty = $item->get_quantity();
    	$remaining_qty = (int) $current_qty - (int) $bought_qty;
    	$macros["remaining-qty"] = $remaining_qty;
    	return $macros;
    }
    

    Important note:
    This snippet calculated the remaining quantity based on the current quantity of purchased product and NOT the stock amount of product at the time user placed the order. If you wish to not calculate based on the live stock amount value, you should save quantity amount of each line item when user places order and then retrieve it to calculate and show on invoice.

    Thread Starter arndofiore80

    (@arndofiore80)

    I followed the procedure, and I inserted in the default folder both a prova.row and a prova.row.tpl file containing the code you provided.
    But when I went to modify the template instead of going out a number, the words “remaining-qty” came out

    *I added the template, and it displays correctly

    Plugin Author Pepro Dev. Group

    (@peprodev)

    So, the problem is solved?

    Thread Starter arndofiore80

    (@arndofiore80)

    No this didn’t work, as no number is displayed, but the code { { {remaining-qty} } }

    Plugin Author Pepro Dev. Group

    (@peprodev)

    Dear @arndofiore80, you should use the macro like other macros, with three opening and three closing curly braces, without any space between. The reason we put it like { { {remaining-qty} } } is because the WordPress forum does not allow us to use more than one curly brace attached to a word.

    Please ignore slashes in the following line and use a macro like:
    {{\{remaining-qty\}}}

    Thread Starter arndofiore80

    (@arndofiore80)

    Sure, here it is.
    I also divided the brackets for the wordpress forum.
    But when entering the code this is entered in the correct way.

    But the display remains that of the code, and not of the possible number that should be displayed.

    Plugin Author Pepro Dev. Group

    (@peprodev)

    Thread Starter arndofiore80

    (@arndofiore80)

    ok, perfect I managed to get the result. Thanks millet

    Plugin Author Pepro Dev. Group

    (@peprodev)

    You are welcome.
    I’m closing the topic.
    If there’s anything else please let me know.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Add Custom Macro’ is closed to new replies.