85 lines
2.8 KiB
PHP
85 lines
2.8 KiB
PHP
|
<?php
|
||
|
|
||
|
function mep_output_add_to_cart_custom_fields() {
|
||
|
global $post, $product;
|
||
|
$pid = $post->ID;
|
||
|
$count=1;
|
||
|
$mep_events_extra_prices = get_post_meta($post->ID, 'mep_events_extra_prices', true);
|
||
|
if ( $mep_events_extra_prices ){
|
||
|
foreach ($mep_events_extra_prices as $field) {
|
||
|
?>
|
||
|
<label class='event_addt_price' for="eventp<?php echo $count; ?>">
|
||
|
<input id="eventp<?php echo $count; ?>" class='event_addt_price_list' type="checkbox" data-price="<?php echo $field['option_price']; ?>" name='event_addt_price[]' value='<?php echo str_replace(' ', '-',$field['option_name'])."_".$field['option_price']; ?>'><?php echo $field['option_name']; ?> - <?php echo get_woocommerce_currency_symbol().$field['option_price']; ?>
|
||
|
</label>
|
||
|
<?php
|
||
|
$count++;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
add_action( 'event_kaku_before_reg_btn', 'mep_output_add_to_cart_custom_fields', 10 );
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
function mep_add_custom_fields_text_to_cart_item( $cart_item_data, $product_id, $variation_id ) {
|
||
|
$tp = get_post_meta($product_id,'_price',true);
|
||
|
|
||
|
if (isset($_POST['add-to-cart'])) {
|
||
|
$name = $_POST['event_addt_price'];
|
||
|
$count =1;
|
||
|
foreach ($name as $color){
|
||
|
$cart_item_data["AddtP_".$count] = $color;
|
||
|
$price = mep_get_item_price($color);
|
||
|
$tp = ($tp+$price);
|
||
|
$count++;
|
||
|
}
|
||
|
}
|
||
|
$cart_item_data['event_tp'] = $tp;
|
||
|
$cart_item_data['line_total'] = $tp;
|
||
|
$cart_item_data['line_subtotal'] = $tp;
|
||
|
return $cart_item_data;
|
||
|
}
|
||
|
add_filter( 'woocommerce_add_cart_item_data', 'mep_add_custom_fields_text_to_cart_item', 10, 3 );
|
||
|
|
||
|
|
||
|
|
||
|
add_action( 'woocommerce_before_calculate_totals', 'add_custom_price' );
|
||
|
function add_custom_price( $cart_object ) {
|
||
|
|
||
|
foreach ( $cart_object->cart_contents as $key => $value ) {
|
||
|
$cp = $value['event_tp'];
|
||
|
$value['data']->set_price($cp);
|
||
|
$new_price = $value['data']->get_price();
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
function mep_display_custom_fields_text_cart( $item_data, $cart_item ) {
|
||
|
$count =1;
|
||
|
echo "<ul class='event-custom-price'>";
|
||
|
foreach ($cart_item as $_cart_item){
|
||
|
if(!empty($cart_item["AddtP_".$count])){
|
||
|
echo "<li>".mep_get_item_name($cart_item["AddtP_".$count])." - ".get_woocommerce_currency_symbol().mep_get_item_price($cart_item["AddtP_".$count])."</li>";
|
||
|
}
|
||
|
$count++;
|
||
|
}
|
||
|
echo "</ul>";
|
||
|
return $item_data;
|
||
|
}
|
||
|
add_filter( 'woocommerce_get_item_data', 'mep_display_custom_fields_text_cart', 10, 2 );
|
||
|
|
||
|
|
||
|
function mep_add_custom_fields_text_to_order_items( $item, $cart_item_key, $values, $order ) {
|
||
|
$count =1;
|
||
|
|
||
|
foreach ($values as $_values){
|
||
|
|
||
|
$item->add_meta_data( __( mep_get_item_name($values["AddtP_".$count]), 'atn' ), get_woocommerce_currency_symbol().mep_get_item_price($values["AddtP_".$count]) );
|
||
|
$count++;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
add_action( 'woocommerce_checkout_create_order_line_item', 'mep_add_custom_fields_text_to_order_items', 10, 4 );
|