Skip to content

Instantly share code, notes, and snippets.

@fbmoises
Last active November 23, 2017 11:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fbmoises/f82e3b4a86f326c64ce44d9952011d1f to your computer and use it in GitHub Desktop.
Save fbmoises/f82e3b4a86f326c64ce44d9952011d1f to your computer and use it in GitHub Desktop.
Comprobar si el cliente ya ha comprado un producto. Muestra un mensaje al cliente debajo del producto que ya ha comprado anteriormente.
// Comprobar si el cliente ya ha comprado un producto. Muestra un mensaje al cliente debajo del producto que ya ha comprado anteriormente.
add_action ( 'woocommerce_after_shop_loop_item', 'wcfb_user_logged_in_product_already_bought', 30);
function wcfb_user_logged_in_product_already_bought() {
if ( is_user_logged_in() ) {
global $product;
$current_user = wp_get_current_user();
if ( wc_customer_bought_product( $current_user->user_email, $current_user->ID, $product->id ) ) {
echo '<div class="user-bought">&hearts; Hola ' . $current_user->first_name . ', has comprado esto anteriormente. ¿Comprar otra vez?</div>';
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment