Skip to content

Instantly share code, notes, and snippets.

@DkCorpBo
Created December 12, 2018 22:47
Show Gist options
  • Save DkCorpBo/adc580208a3859c6aff0294fbc077dc9 to your computer and use it in GitHub Desktop.
Save DkCorpBo/adc580208a3859c6aff0294fbc077dc9 to your computer and use it in GitHub Desktop.
// ----------------boton estado del curso despues de comprar
add_action('wplms_expired_course_button','check_order_please',10,2);
add_action('wplms_take_course_button_html','check_order_please',10,2);
function check_order_please($html,$course_id){
if(!is_user_logged_in())
return $html;
$bought = false;
$status = '';
$desc = '';
$user_id = get_current_user_id();
$course_product_id = get_post_meta($course_id,'vibe_product',true);
$customer_orders = get_posts( array(
'numberposts' => -1,
'meta_key' => '_customer_user',
'meta_value' => $user_id,
'post_type' => 'shop_order', // WC orders post type
'post_status' => 'any' // Only orders with status "completed"
) );
foreach ( $customer_orders as $customer_order ) {
$order_id = method_exists( $order, 'get_id' ) ? $order->get_id() : $order->id;
$order = wc_get_order( $customer_order );
// Iterating through each current customer products bought in the order
foreach ($order->get_items() as $item) {
// WC 3+ compatibility
if ( version_compare( WC_VERSION, '3.0', '<' ) )
$product_id = $item['product_id'];
else
$product_id = $item->get_product_id();
// Your condition related to your 2 specific products Ids
if ( $product_id == $course_product_id && $customer_order->post_status != 'wc-completed') {
$bought = true;
$status = $order->get_status();
$status = str_replace('wc-', '', $status);
$status = str_replace('-', ' ', $status);
$status = strtoupper($status);
break;
}
}
}
if($bought){
if($status = 'ON HOLD')
{
$status = 'EN ESPERA';
$desc = '<p style="margin-top: -10px; font-size: 11px; color: red;">* Presiona el boton para notificar que realizo el Deposito</p>';
}
$html = '<a href="https://semditec.com/notificar-transferencia-bancaria/" class="button full course_button">'.str_replace('wc-', '', $status).'</a>'.$desc;
}
return $html;
}
//----------------------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment