Skip to content

Instantly share code, notes, and snippets.

@odessy
Created November 26, 2018 15:30
Show Gist options
  • Save odessy/f28b2b5c14fea33d7fe694e4b1a565b9 to your computer and use it in GitHub Desktop.
Save odessy/f28b2b5c14fea33d7fe694e4b1a565b9 to your computer and use it in GitHub Desktop.
sample of adding upsell order notes
<?php
add_action('wc_1cu_after_item_add', 'update_order_meta_after_add', 10,1);
function update_order_meta_after_add($order){
if(!empty($_GET['offer_notes']) ){
//assume the last order item added.
$items = $order->get_items();
end($items);
$item_id = key($items);
wc_add_order_item_meta( $item_id, 'upsell_order_notes', sanitize_text_field($_GET['offer_notes']));
}
}
add_shortcode( 'upsell_order_notes', 'upsell_order_notes_func' );
function upsell_order_notes_func($atts){
if(
empty( $_GET['1cu'] ) || empty( $_GET['1cu_s'] )
){
return;
}
ob_start();
?>
<script>
jQuery(function($){
$('.wc_1cu_custom_offer_accept, .wc_1cu_default_offer_accept').hide();
$('#offer_notes_block').find('input[type="submit"]').on('click', function(){
var url = $('a.wc_1cu_custom_offer_accept').attr('href');
var offer_notes = $('#offer_notes_block').find('input[name="offer_notes"]').serialize();
window.location = url + '&' + offer_notes;
return false;
})
});
</script>
<p id="offer_notes_block">
<label for="offer_notes">Notes for Your Designer</label>
<input name="offer_notes" type="text" placeholder="">
<input type="submit" value="Accept Offer">
</p>
<?php
return ob_get_clean();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment