پارس‌کدرز چگونه کار می‌کند؟

از پارس‌کدرز بیشترین بهره را ببرید و رویای کاری خود را زندگی کنید.

پارس‌کدرز خریداران یا کارفرمایان را به مجری‌ها /فریلنسرهای خبره‌ای متصل می‌کند که برای انجام پروژه آماده هستند.

شخصی سازی افزونه ووکامرسی و نمایش قیمت در صفحات ووکامرسی

دو سال پیش منتشر شده

تعداد بازدید: 639

کد پروژه: 239632


شرح پروژه

باسلام

موارد شخصی سازی افزونه که کلا به چند خط نمیرسه

نام افزونه : force default variant به صورت کاملا اپن میباشد و دست فریلنسر ، کاملا باز می باشد. توضیحات افزونه و کدهای افزونه در صفحه زیر می باشد

https://happykite.co.uk/blog/how-to-change-the-default-variant-in-woocommerce/

https://wordpress.org/plugins/force-default-variant-for-woocommerce/

عملکرد این افزونه بدین صورت می باشد که کمترین قیمت اپشن های هر کالا را پیدا و اتوماتیک انتخاب میکند و به مشتری نشان می دهد و همچنین مشتری می تواند اپشن های دیگر را ، دستی انتخاب کند

موارد شخصی سازی : 

1-سازگاری با قالب بیگی کالا و ووکامرس و پی اچ پی جدید و احتمالا رفع تداخل با سایر افزونه  ها 

2-برای نشان دادن متغیرها ، ابتدا قیمت دار بودن متغیر و سپس موجود بودن و سپس اعمال گزینه respect و در غیر این صورت ادامه دادن کد

3-مشکل قالب اینه که در صفحات ارشیو و صفحه اول و صفحات محصول ، کمترین قیمت نشان داده نمیشود 

احتمالا کد رو باید به این صورت اصلاح کنید 

$product = wc_get_product($product_id); $current_products = $product->get_children();

به 

$product = wc_get_product($product_id); $variations = $product->get_available_variations(); $variations_id = wp_list_pluck( $variations, 'variation_id' );

باید بتونید این کد زیر رو ، تحلیل و تغییر بدید . همین 

<?php /* Variant DropDown menu changes */

if ( hpy_fdv_wc_version_check( '3.0' ) ) {

 add_filter( 'woocommerce_product_get_default_attributes', 'hpy_fdv_default_attribute', 10, 1 );

 add_filter( 'woocommerce_dropdown_variation_attribute_options_args', 'hpy_fdv_attribute_args_v2', 10, 1 );

} else {

 add_filter( 'woocommerce_dropdown_variation_attribute_options_args', 'hpy_fdv_attribute_args', 10, 1 );

}




/**

 * Re-order the variations depending on the chosen option. If nothing is set default to ID.

 *

 * @param array $args

 *

 * @return array

 */

function hpy_fdv_attribute_args( $args = array() ) {

 $sortby = !empty( get_option( 'hpy_variant_sort' ) ) ? get_option( 'hpy_variant_sort' ) : 'id';

 $product = $args['product'];

 $attribute = strtolower( $args['attribute'] );

 $product_class = new WC_Product_Variable( $product );

 $children = $product_class->get_visible_children();

 $i = 0;

 if ( !empty( $children ) ) {

  foreach ( $children as $child ) {

   $required = 'attribute_' . $attribute;

   $meta = get_post_meta( $child );

   $to_use = $meta[ $required ][ 0 ];

   $product_child = new WC_Product_Variation( $child );

   $prices[ $i ] = array( $product_child->get_price(), $to_use );

   $i ++;

  }

  if ( $sortby == 'price-low' || $sortby == 'price-high' ) {

   if ( isset( $prices ) ) {

    if ( $sortby == 'price-low' ) {

     sort( $prices );

    } else {

     rsort( $prices );

    }

   }

  }

  $args[ 'selected' ] = $prices[ 0 ][ 1 ];

  $args[ 'show_option_none' ] = '';

 }

 return $args;

}

/**

 * Re-order the variations depending on the chosen option. If nothing is set default to ID.

 *

 * @param array $args

 *

 * @return array

 */

function hpy_fdv_attribute_args_v2( $args = array() ) {

 if ( get_option('hpy_disabled_auto_remove_dropdown') == 'yes' ) {

  return $args;

 }

 $args[ 'show_option_none' ] = false;

 return $args;

}

function hpy_fdv_default_attribute( $defaults ) {

 global $product;

 if ( !$product ) {

  return $defaults;

 }

 if ( $product->post_type !== 'product' ) {

  return $defaults;

 }

 $respect = get_option( 'hpy_variant_respect' );

 $sortby = apply_filters( 'hpy_fdv_custom_sortby', !empty( get_option( 'hpy_variant_sort' ) ) ? get_option( 'hpy_variant_sort' ) : 'id' );

 $thensort = apply_filters( 'hpy_fdv_custom_then_sortby', !empty( get_option( 'hpy_variant_then_sort' ) ) ? get_option( 'hpy_variant_then_sort' ) : 'default' );

 $hide_oos = 'yes' == get_option( 'woocommerce_hide_out_of_stock_items' );

 if ( $respect == 'yes' && !empty( $defaults ) ) {

  return $defaults;

 }

 if ( empty( $sortby ) ) {

  $sortby = 'id';

 }

 if ( !$product->is_type( 'variable' ) ) {

  return $defaults;

 }

 $children = $product->get_children();

 $attributes = array();

 foreach( $children as $key => $child ) {

  $_child = wc_get_product( $child );

  $position = array_search( $key, array_keys( $children ) );

  $stock_qty = $_child->get_stock_quantity();

  $sales = $_child->get_total_sales();

  $stock_status = $_child->is_in_stock();

  if ( $hide_oos && !$stock_status ) {

   //If Hide out of Stock is set, and this variant is out of stock, then skip.

   continue;

  }

  if ( $_child->get_status() == 'publish' ) {

   $attributes[] = apply_filters( 'hpy_fdv_build_attribute_filter', array( 'price' => !empty($_child->get_price()) ? $_child->get_price() : '0' , 'id' => $_child->get_id(), 'position' => $position, 'sales' => $sales, 'stock_level' => $stock_qty ) );

  }

 }

 $secondary_sort = false;

 switch( $sortby ) {

  case 'price-low':

   $secondary_sort = true;

   $attributes = hpy_fdv_multidimensional_sort( $attributes, 'price-low' );

   break;

  case 'price-high':

   $secondary_sort = true;

   $attributes = hpy_fdv_multidimensional_sort( $attributes, 'price-high' );

   break;

  case 'position':

   $attributes = hpy_fdv_multidimensional_sort( $attributes, 'position' );

   break;

  case 'id' :

   $attributes = hpy_fdv_multidimensional_sort( $attributes, 'id' );

   break;

  default:

   $secondary_sort = apply_filters( 'hpy_fdv_do_secondary_sort', true );

   $attributes = apply_filters( 'hpy_fdv_trigger_sort', $attributes );

   break;

 }

 if ( empty( $attributes ) ) {

  return $defaults;

 }

 if ( $secondary_sort ) {

  $attributes = hpy_fdv_secondary_sort( $attributes, $thensort, $sortby );

 }

 $stock_status = array();

 $count = count( $attributes );

 for( $i = 0; $i < $count; $i++ ) {

  $_prod = wc_get_product( $attributes[$i]['id'] );

  $stock_limit = get_option( 'hpy_variant_stockLimit' );

  if ( !empty( $stock_limit ) ) {

   $stock_qty = $_prod->get_stock_quantity();

   if ( $stock_qty < $stock_limit && !is_null( $stock_qty ) ) {

    $stock = 'outofstock';

   } else {

    $stock = $_prod->get_stock_status();

   }

  } else {

   $stock = $_prod->get_stock_status();

  }

  if ( $stock == 'outofstock' ) {

   $stock_status[$i] = 'outofstock';

  } else {

   $stock_status[$i] = 'instock';

  }

 }

 if ( count( array_unique( $stock_status ) ) > 1 && count( array_unique( $stock_status ) ) < count( $attributes ) ) {

  foreach( $stock_status as $key => $value ) {

   if ( $value == 'outofstock' ) {

    unset( $attributes[$key] );

   }

  }

 }

 $attributes = array_values($attributes);

 $_prod = !empty( $attributes[0]['id'] ) ? wc_get_product( $attributes[0]['id'] ) : false;

 if ( empty( $_prod ) ) {

  return apply_filters( 'hpy_fdv_attributes_return', $defaults );

 }

 $attr = hpy_fdv_populate_empty_attributes( $_prod->get_attributes(), $_prod );

 $defaults = array();

 foreach( $attr as $key => $value ) {

  $defaults[$key] = $value;

 }

 return apply_filters( 'hpy_fdv_attributes_return', $defaults );

}

function hpy_fdv_secondary_sort( $attributes, $sortby, $origial_sort ) {

 $attribute_split = array();

 foreach( $attributes as $akey => $avalue ) {

  $attribute_split[$avalue['price']][] = $avalue;

 }

 foreach( $attribute_split as $skey => $split ) {

  switch ( apply_filters( 'hpy_fdv_secondary_sort_switch', $sortby ) ) {

   //Sort using the Secondary filter - Currently defaults to Position, so don't change anything if set to Position

   case 'then_sales':

    $split = hpy_fdv_multidimensional_sort( $split, 'sales' );

    break;

   case 'then_id':

    $split = hpy_fdv_multidimensional_sort( $split, 'id' );

    break;

   case 'then_stock' :

    $split = hpy_fdv_multidimensional_sort( $split, 'stock' );

    break;

   default:

    $split = apply_filters( 'hpy_fdv_trigger_sort', $split );

    break;

  }

  $attribute_split[$skey] = $split;

 }

 $attributes = hpy_fdv_array_flatten( $attribute_split );

 return apply_filters( 'hpy_fdv_secondary_sort_filter', $attributes );

}

function hpy_fdv_array_flatten($array) {

 if (!is_array($array)) {

  return FALSE;

 }

 $result = array();

 foreach ($array as $key => $value) {

  if (is_array($value)) {

   $result = array_merge($result, $value);

  }

  else {

   $result[$key] = $value;

  }

 }

 return $result;

}

function hpy_fdv_populate_empty_attributes( $attributes, $product ) {

 foreach( $attributes as $a_key => $a_value ) {

  if ( empty( $a_value ) ) {

   $parent_id = wc_get_product( $product->get_id() )->get_parent_id();

   if ( strpos( $a_key, 'pa_' ) !== false ) {

    $attrs = wc_get_product_terms( $parent_id, $a_key, array( 'fields' => 'names' ) );

   } else {

    $attrs = hpy_fdv_get_product_attributes( $parent_id, $a_key );

   }

   $attr = array_shift( $attrs );

   if ( !empty( $attr ) ) {

    $attributes[$a_key] = strtolower( str_replace( ' ', '_', $attr ) );

   }

  }

 }

 return apply_filters( 'hpy_fdv_empty_attribute_return', $attributes );

}

function hpy_fdv_get_product_attributes( $product_id, $a_key ) {

 $attributes = get_post_meta( $product_id, '_product_attributes', true )[$a_key];

 $attribute_array = array();

 if ( !empty( $attributes['value'] ) ) {

  $attribute_array = explode( '|', str_replace( ' | ', '|', $attributes['value'] ) );

 }

 return $attribute_array;

}

function hpy_fdv_multidimensional_sort( $array, $check ) {

 if ( $check == 'price-low' ) {

  usort( $array, 'hpy_fdv_sortByPrice' );

 } else if ( $check == 'price-high' ) {

  usort( $array, 'hpy_fdv_sortByPriceHigh' );

 } else if ( $check == 'position' ) {

  usort( $array, 'hpy_fdv_sortByPosition' );

 } else {

  usort( $array, 'hpy_fdv_sortByID' );

 }

 return apply_filters( 'hpy_fdv_sort_filter', $array );

}

function hpy_fdv_sortByPrice($a, $b) {

 return $a['price'] - $b['price'];

}

function hpy_fdv_sortByPriceHigh($a, $b) {

 return $b['price'] - $a['price'];

}

function hpy_fdv_sortByPosition($a, $b) {

 return $a['position'] - $b['position'];

}

function hpy_fdv_sortByID($a, $b) {

 return $a['id'] - $b['id'];

}

add_filter( 'woocommerce_hide_invisible_variations', 'hpy_fdv_hide_invisible_variants' );

function hpy_fdv_hide_invisible_variants() {

 return apply_filters( 'hpy_fdv_hide_unavailable_variants', true );

}

مهارت ها و تخصص های مورد نیاز


بودجه

100,000 تومان تا 300,000 تومان

مهلت برای انجام

1روز

وضعیت مناقصه

بسته


درباره کارفرما

عضویت ده سال پیش

16 پروژه ثبت شده ،
0 پروژه در حال انجام ،
0 پروژه آماده دریافت پیشنهاد ،
نرخ پذیرش پیشنهاد 19%

برای پیدا کردن پروژه‌های مشابه ثبت نام کنید و پروفایل خود را بسازید.

ورود با گوگل
یا
نام نباید خالی باشد.
نام خانوادگی نباید خالی باشد.

نیاز به استخدام فریلنسر یا سفارش پروژه مشابه دارید؟

سفارش پروژه مشابه

قادر به انجام این پروژه هستید؟

ثبت نام کنید

مهلت ارسال پیشنهاد قیمت برای این پروژه تمام شده است

سری به پروژه‌های مشابه بزنید

روش کار در پارس‌کدرز

به رایگان یک حساب کاربری بسازید

مهارت‌ها و تخصص‌های خود را ثبت کنید، رزومه و نمونه‌کارهای خود را نشان دهید و سوابق کاری خود را شرح دهید.

به شیوه‌ای که دوست دارید کار کنید

برای پروژه‌های دلخواه در زمان دلخواه پیشنهاد قیمت خود را ثبت کنید و به فرصت‌های شغلی منحصر به فرد دسترسی پیدا کنید.

با اطمینان دستمزد دریافت کنید

از زمان شروع کار تا انتهای کار به امنیت مالی شما کمک خواهیم کرد. وجه پروژه را از ابتدای کار به امانت در سایت نگه خواهیم داشت تا تضمین شودکه بعد از تحویل کار دستمزد شما پرداخت خواهد شد.

می‌خواهید شروع به کار کنید؟

یک حساب کاربری بسازید


بهترین مشاغل فریلنسری را پیدا کنید
رشد شغلی شما به راحتی ایجاد یک حساب کاربری رایگان و یافتن کار (پروژه) متناسب با مهارت‌های شما است.

پیدا کردن کار (پروژه)

تماشای دمو روش کار