my customer wants the shop "customers" (which are resellers in a b2b-shop) to be able to order every product for a variable number of stores for which he is responsible. If, for example, he has 3 stores, he wants
Store 1: 10 (qty)
Store 2: 10
Store 3: 5
and the regular WC amount field with +/- next to the big "add to cart" button should automatically update (to 25 in this case).
So I added some text fields to the single product view, below the thumbnails with this:
add_action( 'woocommerce_product_thumbnails', 'store_selector' );
function store_selector() {
$stores = get_stores();
echo '<div itemprop="store-selector" class="store-selector" style="font-size: 14px;">';
echo '<div class="product-border fusion-separator sep-"></div>';
echo '<input type='text' class='amount_per_store' name='amount_ps_".$store_id."' id='amount_ps_".$store_id."'>"'
echo '<br></div>';
}
So now I can loop through the fields, add them all up, and write the result to the big add-to-cart-field with simple jQuery. Works well.
But the Problem is: I don't seem able to access my custom fields later! All I can see is the "25", but not the order numbers for single stores. Of course not...WooCommerce does not really know my custom fields!
Maybe I should do something like this:
woocommerce_form_field( 'my_field_name', array(
'type' => 'text',
'class' => array('amount_per_store'),
'label' => __('Store '.$store_id),
'placeholder' => __(''),
), $checkout->get_value( 'my_field_name' ));
I foud this here: https://docs.woocommerce.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/ ...it's an example of how to add custom fields to other places.
I am a bit stuck at the moment because I don't know how to add custom fields for products the right way!
-A customer should be able to correct / edit his order and change the value of the custom fields when he goes back. -Values should be carried through the ordering process, appear on the order confirmation page, in the order emails and also in the order details in the backend.
Any help is greatly acknowledged!