Skip to content

Instantly share code, notes, and snippets.

@RiFi2k
Created April 11, 2017 04:05
Show Gist options
  • Save RiFi2k/2373be7a207a613f95088ba064718af3 to your computer and use it in GitHub Desktop.
Save RiFi2k/2373be7a207a613f95088ba064718af3 to your computer and use it in GitHub Desktop.
//add_action( 'template_redirect', 'usasf_check_forsale' );
function usasf_check_forsale() {
if ( is_singular( 'tribe_events' ) ) {
$post_object = get_queried_object();
$post_id = get_queried_object_id();
$regional = get_field( 'is_regional_event', $post_id );
if ( ! $regional ) {
return;
}
$discount = get_field( 'discount_pricing', $post_id );
if ( ! $discount ) {
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();
wp_reset_query();
add_action( 'usasf_error_message_forsale', 'usasf_forsale_content' );
return;
}
}
add_action( 'usasf_error_message_notforsale', 'usasf_notforsale_content' );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment