훅 사용 가이드
Ultimate Multisite는 200개 이상의 액션 훅과 280개 이상의 필터 훅을 제공합니다. 이 페이지는 가장 자주 사용되는 훅을 실용적인 예시와 함께 다룹니다. 완전한 자동 생성된 참조를 보려면 이 섹션의 다른 페이지를 확인하세요.
액션 훅
고객 수명 주기
고객 생성 후
/**
* @param WP_Ultimo\Models\Customer $customer
*/
add_action('wu_customer_post_create', function($customer) {
wp_mail(
$customer->get_email(),
'Welcome!',
'Thanks for joining our platform!'
);
});
고객 상태 변경
/**
* @param WP_Ultimo\Models\Customer $customer
* @param string $old_status
* @param string $new_status
*/
add_action('wu_customer_status_change', function($customer, $old_status, $new_status) {
// React to status transitions
}, 10, 3);
사이트 훅
사이트 게시 후
/**
* @param WP_Ultimo\Models\Site $site
* @param WP_Ultimo\Models\Membership $membership
*/
add_action('wu_site_published', function($site, $membership) {
switch_to_blog($site->get_id());
activate_plugin('essential-plugin/essential-plugin.php');
restore_current_blog();
}, 10, 2);
템플릿 적용 전
/**
* @param int $site_id
* @param int $template_id
*/
add_action('wu_before_apply_template', function($site_id, $template_id) {
switch_to_blog($site_id);
if ($template_id === 5) {
update_option('woocommerce_store_setup', 'complete');
}
restore_current_blog();
}, 10, 2);
멤버십 훅
상태 전환
add_action('wu_membership_status_to_active', function($membership) {
// Membership activated
});
add_action('wu_membership_status_to_expired', function($membership) {
$sites = $membership->get_sites();
foreach ($sites as $site) {
$site->set_status('suspended');
$site->save();
}
});
결제 훅
결제 완료 / 실패
add_action('wu_payment_completed', function($payment) {
// Handle successful payment
});
add_action('wu_payment_failed', function($payment, $error_message) {
$admin_email = get_option('admin_email');
wp_mail(
$admin_email,
'Payment Failed',
sprintf('Payment #%d failed: %s', $payment->get_id(), $error_message)
);
}, 10, 2);
체크아웃 훅
처리 전 / 완료 후
/**
* @param WP_Ultimo\Checkout\Cart $cart
*/
add_action('wu_checkout_before_processing', function($cart) {
// Validate or modify cart before processing
});
/**
* @param WP_Ultimo\Models\Payment $payment
* @param WP_Ultimo\Models\Customer $customer
* @param WP_Ultimo\Models\Membership $membership
*/
add_action('wu_checkout_completed', function($payment, $customer, $membership) {
// Track conversion, send notifications, etc.
}, 10, 3);
도메인 훅
add_action('wu_domain_mapped', function($domain) {
// Update CDN or DNS configuration
});
add_action('wu_domain_ssl_verified', function($domain) {
// SSL certificate verified for domain
});
필터 훅
가격 필터
장바구니 합계
add_filter('wu_cart_total', function($total, $cart) {
$customer = $cart->get_customer();
if ($customer && $customer->is_vip()) {
$total = $total * 0.9; // 10% VIP discount
}
return $total;
}, 10, 2);
세율
add_filter('wu_tax_rate', function($rate, $country, $state) {
if ($country === 'US' && $state === 'CA') {
return 0.0875;
}
return $rate;
}, 10, 3);
템플릿 필터
add_filter('wu_available_templates', function($templates, $customer) {
if (!$customer->is_vip()) {
foreach ($templates as $key => $template) {
if ($template['category'] === 'premium') {
unset($templates[$key]);
}
}
}
return $templates;
}, 10, 2);
제한 필터
add_filter('wu_limitation_feature_allowed', function($allowed, $site_id, $membership) {
if ($membership->get_customer()->is_vip()) {
return true;
}
return $allowed;
}, 10, 3);
add_filter('wu_disk_space_limit', function($limit, $site_id, $membership) {
if ($membership->get_days_active() > 365) {
$limit += 500; // Extra 500MB for long-term customers
}
return $limit;
}, 10, 3);