-
-
Save amaraa87/917d1ac1c87439a6c52955e9d7f3a9bf to your computer and use it in GitHub Desktop.
wordpress form 7 custom tag and include mail with woo
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
<?php | |
if( ! is_admin() ) { | |
add_action( 'wpcf7_init', 'custom_add_form_tag_travel' ); | |
function custom_add_form_tag_travel() { | |
wpcf7_add_form_tag( 'travel_name', 'custom_add_form_tag_travel_handler' ); | |
} | |
function custom_add_form_tag_travel_handler( $tag ) { | |
return get_travel_name(); | |
} | |
// add_filter('wpcf7_special_mail_tags', 'wpcf7_tag_post', 10, 3); | |
// function wpcf7_tag_post($output, $name, $html) | |
// { | |
// $name = preg_replace('/^wpcf7\./', '_', $name); | |
// if ('travel-name' == $name) { | |
// return get_travel_name(); | |
// } | |
// return $output; | |
// } | |
function get_travel_name(){ | |
global $woocommerce; | |
$data; | |
$items = $woocommerce->cart->get_cart(); | |
foreach($items as $item => $values) { | |
$_product = wc_get_product( $values['data']->get_id()); | |
$data .= '<div id="currenttravelid">'.$_product->get_title().'</div>'; | |
} | |
return $data; | |
} | |
} | |
add_filter( 'woocommerce_add_to_cart_validation', 'remove_cart_item_before_add_to_cart', 20, 3 ); | |
function remove_cart_item_before_add_to_cart( $passed, $product_id, $quantity ) { | |
if( ! WC()->cart->is_empty() ) | |
WC()->cart->empty_cart(); | |
return $passed; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment