Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have to set up a woocommerce-store for a friend, he delivers drinks to customers. Here in germany we have a refund per case, for Beer it is 3.60 €.

Now my problem is how to calculate the refund in the cart and bills.

I`ve managed to create a field below the product-price, but I am failing on calculating it.

Thats how far I got:

This function creates the field on the product-page in backend:

function add_custom_price_box() {
    woocommerce_wp_text_input(array('id' => '_pfand_price', 'class' => 'wc_input_pfand_price short', 'label' => __('Pfand', 'woocommerce') . ' (' . get_woocommerce_currency_symbol() . ')', 'type' => 'number', 'custom_attributes' => array(
        'step' => 'any',
        'min' => '0'
    )));
}
add_action('woocommerce_product_options_pricing', 'add_custom_price_box');

Save the value:

function custom_woocommerce_process_product_meta($post_id, $post) {
    update_post_meta($post_id, '_pfand_price', stripslashes($_POST['_pfand_price']));
}
add_action('woocommerce_process_product_meta', 'custom_woocommerce_process_product_meta', 2, 2);

Display Value on single-product:

function add_custom_price_front($p, $obj) {

$post_id = $obj->post->ID;

$link = get_permalink($post_id);
$pfand = get_post_meta($post_id, '_pfand_price', true);

if (is_admin()) {
    $tag = 'div'; //show in new line
} else {
    $tag = 'span';
}

if (!empty($pfand)) {
    $additional_price.= "<$tag style='font-size:80%' class='pfand_price'> (" . get_woocommerce_currency_symbol() . "zzgl. Pfand = $pfand)</$tag>";
}

return "<a href='$link'>" . $p . $additional_price . "</a>";
}
add_filter('woocommerce_get_price_html', 'add_custom_price_front', 10, 2);

Live Example can be seen here:

http://niendorfergetraenke-preisfuchs.de/shop/bier/tata-20-x-050-liter/

Any help much appreciated.

share|improve this question
add comment

closed as off-topic by Chip Bennett, helgatheviking, toscho Apr 13 at 16:37

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

protected by Community Apr 13 at 15:14

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Browse other questions tagged or ask your own question.