Skip to content

Instantly share code, notes, and snippets.

@RiFi2k
Created April 11, 2017 02:13
Show Gist options
  • Save RiFi2k/4c2142d164d75d410db59d2a9f378746 to your computer and use it in GitHub Desktop.
Save RiFi2k/4c2142d164d75d410db59d2a9f378746 to your computer and use it in GitHub Desktop.
//add_action( 'save_post_tribe_events', 'usasf_save_events', 10, 3 );
function usasf_save_events( $post_id, $post, $update ) {
// verify if this is an auto save routine.
// If it is our form has not been submitted, so we dont want to do anything
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return;
// Check permissions
if ( 'page' == $post->post_type ) {
if ( !current_user_can( 'edit_page', $post_id ) )
return;
} else {
if ( !current_user_can( 'edit_post', $post_id ) )
return;
}
$repeater = get_field( 'discount_pricing_range', $post_id );
$current_date = date( 'Ymd' );
$order = array();
// populate order
foreach( $repeater as $i => $row ) {
$order[ $i ] = $row['pricing_range_start_date'];
}
// multisort
array_multisort( $order, SORT_ASC, $repeater );
foreach( $repeater as $repeat ) {
if ( $current_date <= $repeat['pricing_range_end_date'] && $current_date >= $repeat['pricing_range_start_date'] ) {
$product_id = USASFidFromMeta::get_post_id_by_meta_key_and_value( '_tribe_wooticket_for_event', $post_id );
update_post_meta( $product_id, '_regular_price', $repeat['pricing_range_price'] );
update_post_meta( $product_id, '_price', $repeat['pricing_range_price'] );
wc_delete_product_transients();
break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment