Woocommerce Product Order Get Meta Data Not Returning Meta Added With Wc Add Order Item Meta

WooCommerce: добавьте пользовательскую ссылку Metabox на страницу администрирования

В настоящее время я успешно добавляю поле на свои страницы продуктов WooCommerce, которое показывает значение:

  • в корзине (передняя часть),
  • на странице проверки (front end),
  • на странице заказа (передняя часть),
  • и в отдельной странице клиента (задний конец).

Проблема: он не отображается в качестве настраиваемого поля в "настраиваемых полях" администратора "Метабокс" со значением внутри него, а также как текст на странице заказа.

Вот мой рабочий код:

Я думаю, что это последний бит кода, который нуждается в изменении. В настоящее время он отображает текст под элементом заказа, поэтому, возможно, мне нужно настроить wc_add_order_item_meta на что-то еще?

Я пробовал все, но, похоже, не работает. Я могу заставить его работать, когда мое поле находится на странице проверки, но не тогда, когда я вытаскиваю его с страницы продукта.

Возможно, мне не хватает фрагмента процесса проверки?

ОБНОВЛЕНИЕ 2017/11/02(отлично работает в Woocommerce 3 +)

Сначала я получил все ожидаемые работы, , за исключением получения значениядля my_field_name в конце "Пользовательские поля" "Метабокс" на страницах "Заказ".

Затем, после настоящего кошмара, у меня найдено довольно приятное рабочее решение, лучше, чем раньше. В конце у вас теперь есть пользовательский метабокс с настраиваемым полем my_field_name , отображающим правильное значение, как на этом скриншоте:

Мой код разделен на 2 части.

1) backend Metabox на страницах Order, с редактируемым полем, показывающим правильное значение, поступающее из настраиваемого поля на страницах продукта (в интерфейсе):

2) Передний конец/задний конец:

• Пользовательское поле страницы продукта (front end).
• Отображение этих данных на тележке, страницах проверки и благодарность за заказ (передняя часть).
• Отображение данных на странице заказа (назад)

Вопрос: WooCommerce: добавьте пользовательскую ссылку Metabox на страницу администрирования

В настоящее время я успешно добавляю поле на страницы продуктов WooCommerce, которые показывают значение:

  • в тележке (передняя часть),
  • на странице проверки (передняя часть),
  • на странице заказа (передняя часть),
  • и в отдельной странице индивидуального заказа (задний конец).

Проблема: он не отображается как настраиваемое поле в пользовательских полях администратора «Метабокс» со значением внутри него, а также как текст на странице заказа.

Вот мой рабочий код:

Я думаю, что это последний бит кода, который нуждается в изменении. В настоящее время он отображает текст под элементом заказа, поэтому, возможно, мне нужно настроить wc_add_order_item_meta к чему-то еще?

Я пробовал все, но он, похоже, не работает. Я могу заставить его работать, когда мое поле находится на странице проверки, но не тогда, когда я вытаскиваю его со страницы продукта.

Возможно, мне не хватает фрагмента процесса проверки?

ОБНОВЛЕНИЕ 2017/11/02(Отлично работает в Woocommerce 3+)

Сначала я получил все, что ожидало, кроме получения значениядля my_field_name в конце «Пользовательские поля» «Метабокс» на страницах «Заказ».

Затем, после настоящего кошмара, у меня есть нашел довольно приятное рабочее решение, лучше, чем раньше. В конце у вас есть пользовательский метабокс с настраиваемым полем my_field_name отображая правильное значение, как на этом снимке экрана:

Мой код разделен на 2 части.

1) бэкэнд Metabox на страницах заказа, с редактируемым полем, показывающим правильное значение, поступающее из пользовательского поля на страницах продукта (в лицевой части):

2) Передний конец / задний конец:

• Пользовательское поле страницы продукта (передняя часть).
• Отображение этих данных на тележке, страницах проверки и благодарность за заказ (передняя часть).
• Отображение данных на странице заказа (назад)

WooCommerce installment payments part 1

Posted on June 02, 2016

Installment payments breaks down the full purchase price of items into smaller amounts over periods of time to make purchasing more reachable for high priced items. A recurring billing is used to capture these smaller payments. There are 2 existing WooCommerce plugins which can help achieve this behavior. The first is WooCommerce Deposits. The other is WooCommerce Subscriptions. There are shortcomings to both plugins which I will discuss below. Finally, I will describe a custom implementation which was deployed successfully on a customer site that overcomes these shortcomings as well as a bonus in providing dynamic calculations of installments. Developers can use this article as a guide to implement their own solutions.

WooCommerce Installment Payments – a custom implementation

Shortcomings of existing plugin solutions

WooCommerce Deposits provides installment payments behavior by allowing customers to choose a pre-defined payment plan for a specific product in WooCommerce. However, there are 3 shortcomings. First, the store admin must setup 1 or more payment schedules for each product that they wish to offer an installment payment plan for. For stores with many and varied price items, this can be a tedious chore. What if prices of items change? These payment schedules must change as well. Second, how would coupon discounts be supported for installment purchases if payment schedules and amounts must be pre-defined? Finally, the biggest issue of all is recurring billing relies on the customer manually logging into the system to make the payment as opposed to automatically billing the customer every period. With that said, WooThemes is working on automating the recurring billing but it is not available as of this writing. When automatic recurring billing becomes available, this plugin can be considered for installment payments as long as the other 2 limitations are understood.

WooCommerce Subscriptions is designed for subscription based selling. But it can be used to implement installments by allowing the user to purchase pre-defined billing schedules and the plugin will manage the recurring billing. The system can be customized to cancel the recurring billing, and thus the subscription once the total amount captured from recurring billing equals the full price of the item. This method of offering installment payments still has the problem of having the store admin create these pre-defined billing schedules. I am unsure if coupon discounts work, but the plugin says, “Delight customers by offering subscribers special discounts on their payments or sign-up fee”.

Installment payments custom implementation

The idea behind the custom implementation is to dynamically calculate the installment payment prices at run-time. The calculations can be based on product price, start date, or any type of logic. With the calculated installment payment price, adjust the cart / checkout in WooCommerce to reflect the installment price if the user selects purchase using installments. Since the installment price is determined at run-time. There will be full support for coupons. This will be accomplished using existing filters and hooks of the stock WooCommerce plugin. Following the normal WooCommerce checkout process, we will record all the future installments details in the database. Finally, an automatic cron job will be configured to run and process any recurring billing based on the installments database table. The rest of the article will describe in detail the custom code in these filters and hooks which are used to complete the WooCommerce side of the solution. In part 2 of this series, we will discuss the recurring billing and implementation.

Requirements

  1. WooCommerce plugin
  2. Advanced Custom Fields plugin
  3. API library of your Payment gateway (For recurring billing)

Hooks and filters used

To begin, we will start with defining the logic on how to break down the full purchase price into equal installments. Here is where the dynamic installment calculations takes place. The example logic used is based on number of months before program start date. Payment in full must be received by the store before the program start date. For example, if a summer camp program begins on August 1, 2016 and today is May 1, 2016. Then there would be 3 months / payments before the program start date. May, June, and July 1st.

Put this logic in the woocommerce_after_add_to_cart_button action which is called on the product detail page after the Add to Cart button. This will clearly show to the customer each individual future payment in an easy to view table. In addition, the user can choose between purchasing the program in full by clicking on the Register in Full button or in installments using the new Register using Installments button.

Add this Javascript function to your site to flag a purchase as an installment purchase. This function will trigger when the user clicks on the new Register and pay with Installment Plan button.

Here is where we will detect that the user clicked on the new Register and pay with Installment Plan button. The next step is to store the installment information into the cart item meta data. We will use the woocommerce_add_cart_item_data filter which is called when add_to_cart is happening on the server side.

Next, we will adjust the price of the program in the cart to reflect the first installment. Add this to the woocommerce_before_calculate_totals action. This action is called by WooCommerce during recalculation of the cart / checkout page grid before any coupons or taxes are applied.

We will also need to store program meta data into the WooCommerce order meta data using woocommerce_add_order_item_meta This action is called during the order creation after checkout completes. The meta is stored permanently in the database table prefix_woocommerce_order_itemmeta for this order. It will also be used after checkout to keep track of future installments which needs to be billed.

As an optional step, you may want to change the program description in the cart show the user that the current payment is 1 of X payments. To change the program description in the cart, we will use the woocommerce_cart_item_name filter.

Installments in action

Regular payment in full and installment purchase is possible at the same time. Coupon processing is also supported. However, you may want to adjust the coupon across all the future installment payments as opposed to applying it once which is the default behavior.

Purchase using installments or in full

If a customer registered on April 1, 2016 for the Youth camp summer experience which starts on August 1, 2016. The installment plan will be a 4 month installment plan as opposed to a 3 month installment plan in the example above.

Four months installments

At this point, the initial installment is complete and fully functioning. The customer can click on the program detail page to view the installment breakdown and choose to purchase using installments. The initial installment will be charged to the user. The last step is to capture the remaining installments using an automatic cron job. We will cover this in part 2 of this series.

Optional styling and UI changes

Change the Add to Cart button label using the woocommerce_product_single_add_to_cart_text filter.

I am available for consultation for WooCommerce installment payments custom implementation. Please navigate over to the contact tab to get in touch. Thank you!

If you have any questions or comments about this article. Please put them in the comments below.

  1. Part 2 of this series will discuss the recurring billing and implementation.
  2. This is only a guide. An implementation as a plugin would be ideal to separate installments logic from the rest of the theme.
  3. I am unaware of PayPal support for recurring billing as of June 21, 2016.

Post navigation

2 thoughts on ” WooCommerce installment payments part 1 ”

This is a great tutorial and exactly what I am looking for my site. Any estimate when you will be posting the part 2 of the tutorial sir. I am trying to use PayPal for gateway. Thanks again

I am unaware of any APIs from PayPal which would make recurring payment capture work. With PayPal, you have to go with the subscriptions method. The way PayPal works is it makes the user go to the PayPal website to process each individual transaction thereby maintaining PCI compliance. If you find anything otherwise, I would be interested in learning more about it.

Leave a Reply

Your email address will not be published. Required fields are marked *