WordPress
- 5 ответов
- 0 вопросов
1
Вклад в тег
add_action('woocommerce_thankyou', 'change_user_role_on_order_success');
function change_user_role_on_order_success($order_id ) {
$order = new WC_Order( $order_id );
$user_id = $order->user_id;
$wp_user_object = new WP_User($user_id);
$items = $order->get_items();
foreach ( $items as $item ) {
$product_name = $item['name'];
$product_id = $item['product_id'];
$product_variation_id = $item['variation_id'];
}
if ( $product_id == '999' && $wp_user_object->roles[0] != "administrator"){ // Не исправлять админа!
wp_update_user( array( 'ID' => $wp_user_object->ID, 'role' => "my-role" ) );
} else
if ( $product_id == '777' && $wp_user_object->roles[0] != "administrator"){ // Не исправлять админа!
wp_update_user( array( 'ID' => $wp_user_object->ID, 'role' => "my-role2" ) );
}
}
function design_shortcode() {
$terms = get_the_terms($post->ID, 'pa_design');
if ($terms && !is_wp_error($terms)) {
foreach ($terms as $term)
$design_name = $term->name;
$design_slug = $term->slug;
}
if ($design_name != ''){
echo do_shortcode( '[product_attribute attribute="design" filter="'.$design_slug.'" per_page="6" columns="6" orderby="rand" order="rand"]' ); }
}
add_shortcode('alldesing', 'design_shortcode');
function primary_color_shortcode() {
$terms = get_the_terms($post->ID, 'pa_primary-color');
if ($terms && !is_wp_error($terms)) {
foreach ($terms as $term)
$primary_color_name = $term->name;
$primary_color_slug = $term->slug;
}
if ($primary_color_name != ''){
echo '<h3 class="main-title uppercase" align="left">Другие товары в цвете '.$primary_color_name.'</h2>'
echo do_shortcode( '[product_attribute attribute="primary-color" filter="'.$primary_color_slug.'" per_page="6" columns="6" orderby="rand" order="rand"]' ); }
}
add_shortcode('allprimarycolor', 'primary_color_shortcode');