تابع ووکامرسی wc_get_shipping_method_count دریافت تعداد روش های حمل و نقل

تابع ووکامرسی wc_get_shipping_method_count – دریافت تعداد روش های حمل و نقل قابل دسترس
Syntax – سینتکس
(int) wc_get_shipping_method_count( (bool) $include_legacy = false );
Parameters – پارامتر ها (1)
- 1- $include_legacy (bool)
Usage – نحوه استفاده
if ( !function_exists( 'wc_get_shipping_method_count' ) ) {
require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-core-functions.php';
}
// Count legacy shipping methods too.
$include_legacy = false;
// NOTICE! Understand what this does before running.
$result = wc_get_shipping_method_count($include_legacy);
Defined – محل تعریف
/includes/wc-core-functions.php
function wc_get_shipping_method_count( $include_legacy = false ) {
global $wpdb;
$transient_name = 'wc_shipping_method_count_' . ( $include_legacy ? 1 : 0 ) . '_' . WC_Cache_Helper::get_transient_version( 'shipping' );
$method_count = get_transient( $transient_name );
if ( false === $method_count ) {
$method_count = absint( $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}woocommerce_shipping_zone_methods" ) );
if ( $include_legacy ) {
// Count activated methods that don't support shipping zones.
$methods = WC()->shipping->get_shipping_methods();
foreach ( $methods as $method ) {
if ( isset( $method->enabled ) && 'yes' === $method->enabled && ! $method->supports( 'shipping-zones' ) ) {
$method_count++;
}
}
}
set_transient( $transient_name, $method_count, DAY_IN_SECONDS * 30 );
}
return absint( $method_count );
}
versions – نسخه ها
از نسخه : 2.6.0
نسخه فعلی : 3.0.6
دیگر نسخه ها : 3.0.6 , 3.0.5 , 3.0.4 , 3.0.3 , 3.0.2
ارسال نظر