I need pass parameters to woocommerce woocommerce_before_add_to_cart_button hook.
In my functions, I have a function that calls:
/** Yiith: evitar pagar dos veces por el mismo depósito, obliga a completar pedido primero **/
if( defined( 'YITH_WCDP' ) && ! function_exists( 'yith_wcdp_skip_deposit_if_there_is_other_deposit' ) ){
function yith_wcdp_skip_deposit_if_there_is_other_deposit( $process_deposit, $product_id ){
/**
* @var $product \WC_Product
*/
if(!is_user_logged_in()){
add_action('woocommerce_before_add_to_cart_button', 'yith_print_link_force_login');
$process_deposit = false;
}
else{
$user_id = get_current_user_id();
$order_ids = yith_get_order_ids_from_bought_items ( $product_id, $user_id );
foreach ( $order_ids as $order_id ){
$suborders = YITH_WCDP_Suborders()->get_suborder( $order_id );
if ( is_array( $suborders ) && !empty( $suborders ) ){
foreach ( $suborders as $suborder_id ) {
$suborder = wc_get_order( $suborder_id );
if (!in_array( $suborder->get_status() , array(
'completed',
'processing',
))) {
add_action('woocommerce_before_add_to_cart_button', 'yith_print_link'); //do_action('woocommerce_before_add_to_cart_button', $order_id);
$process_deposit = false;
}
}
}
}
}
return $process_deposit;
}
add_filter( 'yith_wcdp_is_deposit_enabled_on_product', 'yith_wcdp_skip_deposit_if_there_is_other_deposit', 10, 2 );
}
And it must call yith_print_link, wich looks like:
if( defined( 'YITH_WCDP' ) && ! function_exists( 'yith_print_link' ) ) {
function yith_print_link($order)
{
if($order != null){
$order = "view-order/" . $order . "/#yith_wcdp_deposits_details";
}
else{
$order = "orders/";
}
$link = get_permalink( get_option('woocommerce_myaccount_page_id')) . $order;
echo '<div class="buy-link"><a href="' . $link . '">Pagar matrícula</a></div><style>.single_add_to_cart_button.qbutton.button.alt{display: none!important;}</style>';
echo '<p style="font-weight: 200;">Tienes la plaza pagada, finaliza la matrícula.</p>';
}
}
I'm trying to show a link to an specific order before the cart button in product page if the current logged user had bought this product before.
Thanks, and Regards.