Created
September 27, 2017 12:19
-
-
Save cannap/84f52696db40adcfa62eab84e886133a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function iconic_output_engraving_field() { | |
global $product; | |
if ( ! check_user_role( 'gewerbe' ) ) | |
return; | |
?> | |
<hr> | |
<div class="iconic-engraving-field"> | |
<p class="form-row legal terms wc-terms-and-conditions"> | |
<input type="checkbox" class="input-checkbox" name="duplicating" id="duplicating"> | |
<input type="text" class="input-checkbox" name="duplicating-price" id="duplicating-price"> | |
<label for="duplicating" class="woocommerce-form__label woocommerce-form__label--for-checkbox checkbox"></label> | |
</p> | |
</div> | |
<?php | |
} | |
add_action( 'woocommerce_after_add_to_cart_button', 'iconic_output_engraving_field', 10 ); | |
function iconic_add_engraving_text_to_order_items( $item, $cart_item_key, $values, $order ) { | |
if ( empty( $values['duplicating-price'] ) ) { | |
return; | |
} | |
$item->add_meta_data( __( 'Engraving', 'iconic' ), $values['duplicating-price'] ); | |
} | |
add_action( 'woocommerce_checkout_create_order_line_item', 'iconic_add_engraving_text_to_order_items', 10, 4 ); | |
function iconic_display_engraving_text_cart( $product_name, $cart_item, $cart_item_key ) { | |
PC::debug($cart_item); | |
if ( empty( $cart_item['duplicating-price'] ) ) { | |
return $product_name; | |
} | |
return sprintf( '%s <p><strong>%s</strong>: %s</p>', $product_name, __( 'Engraving', 'iconic' ), $cart_item['duplicating-price'] ); | |
} | |
add_filter( 'woocommerce_cart_item_name', 'iconic_display_engraving_text_cart', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment