WooCommerce نمایش تعداد خرید کاربر در ووکامرس

mehditalaei

تازه وارد
سلام
شورت کدی هست که باهاش بشه تعداد خرید های کاربر رو نمایش داد؟
 

پیام یزدانیان

کاربر عضو
سلام وقت بخیر
این کد را جایی ک میخواید نمایش بدید:

PHP:
<?php
//by-yazdanian
$current_user = wp_get_current_user();
$tedadesefaresh = wc_get_customer_order_count( $current_user->ID );
$args = array(
    'customer_id' => $current_user->ID,
    'post_status' => 'cancelled',
    'post_type' => 'shop_order',
    'return' => 'ids',
);
$tedadcancellshode = 0;
$tedadcancellshode = count( wc_get_orders( $args ) );

$num_not_cancelled = $tedadesefaresh - $tedadcancellshode;

echo 'تعداد سفارش شا : ';
echo $tedadesefaresh;
echo 'می باشد  ';
?>
 
  • Like
واکنش‌ها[ی پسندها]: Mohammad

mehditalaei

تازه وارد
سلام وقت بخیر
این کد را جایی ک میخواید نمایش بدید:

PHP:
<?php
//by-yazdanian
$current_user = wp_get_current_user();
$tedadesefaresh = wc_get_customer_order_count( $current_user->ID );
$args = array(
    'customer_id' => $current_user->ID,
    'post_status' => 'cancelled',
    'post_type' => 'shop_order',
    'return' => 'ids',
);
$tedadcancellshode = 0;
$tedadcancellshode = count( wc_get_orders( $args ) );

$num_not_cancelled = $tedadesefaresh - $tedadcancellshode;

echo 'تعداد سفارش شا : ';
echo $tedadesefaresh;
echo 'می باشد  ';
?>
شورت کد لازم نداره؟
 

پیام یزدانیان

کاربر عضو
اگه میخواید این مقادیر رو با شرتکد نشون بدید : کد زیر رو به فانکشن قالب خود اضافه کنید.
سپس با استفاده از شرتکد : [wooitem] نشون بدید.



PHP:
<?php
/**
 * @snippet       نمایش تعداد محصول خریداری شده توسط کاربر - WooCommerce
 * @author        payam_yazdainain
 * @compatible    Woo 3.5.1 up ...
 * @شرت کد برای نماش :    wooitem
 */
//by-yazdanian
add_shortcode('wooitem', 'payam_yazdainain_kurd_function');
function payam_yazdainain_kurd_function() {
$current_user = wp_get_current_user();
$tedadesefaresh = wc_get_customer_order_count( $current_user->ID );
$args = array(
    'customer_id' => $current_user->ID,
    'post_status' => 'cancelled',
    'post_type' => 'shop_order',
    'return' => 'ids',
);
$tedadcancellshode = 0;
$tedadcancellshode = count( wc_get_orders( $args ) );

$num_not_cancelled = $tedadesefaresh - $tedadcancellshode;

echo 'تعداد سفارش شا : ';
echo $tedadesefaresh;
echo 'می باشد  ';
}
?>



یا
اگه میخواید شرت کدرو تو قالب استفاده کنید از کد زیر استفاده کنید :

PHP:
<?php echo do_shortcode("[wooitem]"); ?>
 

mehditalaei

تازه وارد
اگه میخواید این مقادیر رو با شرتکد نشون بدید : کد زیر رو به فانکشن قالب خود اضافه کنید.
سپس با استفاده از شرتکد : [wooitem] نشون بدید.



PHP:
<?php
/**
* @snippet       نمایش تعداد محصول خریداری شده توسط کاربر - WooCommerce
* @author        payam_yazdainain
* @compatible    Woo 3.5.1 up ...
* @شرت کد برای نماش :    wooitem
*/
//by-yazdanian
add_shortcode('wooitem', 'payam_yazdainain_kurd_function');
function payam_yazdainain_kurd_function() {
$current_user = wp_get_current_user();
$tedadesefaresh = wc_get_customer_order_count( $current_user->ID );
$args = array(
    'customer_id' => $current_user->ID,
    'post_status' => 'cancelled',
    'post_type' => 'shop_order',
    'return' => 'ids',
);
$tedadcancellshode = 0;
$tedadcancellshode = count( wc_get_orders( $args ) );

$num_not_cancelled = $tedadesefaresh - $tedadcancellshode;

echo 'تعداد سفارش شا : ';
echo $tedadesefaresh;
echo 'می باشد  ';
}
?>



یا
اگه میخواید شرت کدرو تو قالب استفاده کنید از کد زیر استفاده کنید :

PHP:
<?php echo do_shortcode("[wooitem]"); ?>
آقا دمت گرم درست شد
سه روزه دنبال همینم پیدا نکردم
خدا خیرت بده
 
بالا