سایت برتر

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

86 بازدیدووکامرس
0
0 دیدگاه

سلام وقتتون بخیر خسته نباشید. من دنیال یک راه حل میگردم که بتوانم سفارشات قبلی مشتری رو نشان بدم در صفحه کاربری هر مشتری ؛ خود پروفایل کاربری ووکامرس این رو نشون میده ولی من یک ناحیه کاربری جداگانه خودم ساختم و از اون میخام به عنوان ناحیه کاربر ی استفاده کنم اما هیچ شورت کدی پیدا نکردم تا بتوانم سفارشات قبلی مشتری را در ناحیه کاربری اضاف گنم… میشه راهنمایی بفرمایید چه باید بکنم؟ برام فرقی نمیکنه شورت کد باشه افزونه باشه کد باشه ،هزینه هم مهم نیست فقط دنبال راه حلم…با تشکر

0
Saeed

سلام دوست عزیز!

درسته بصورت پیش فرض این امکان وجود نداره حتی شورتکد اون!

اما پیشنهاد من استفاده از کد هستش که یک مقاله از یک سایت این مورد رو آموزش داده که با فیلترشکن وارد این سایت

بشید و موارد رو پیش ببرید.

موفق و پیروز باشید.

0
علی حق نگهدار

سلام.

می تونید از این کد در پوشه توابع وبسایتتون استفاده کنید

<code class="language-php"><span class="token function">add_filter</span> <span class="token punctuation">(</span> <span class="token string single-quoted-string">'woocommerce_account_menu_items'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'misha_purchased_products_link'</span><span class="token punctuation">,</span> <span class="token number">40</span> <span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token function">add_action</span><span class="token punctuation">(</span> <span class="token string single-quoted-string">'init'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'misha_add_products_endpoint'</span> <span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token function">add_action</span><span class="token punctuation">(</span> <span class="token string single-quoted-string">'woocommerce_account_purchased-products_endpoint'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'misha_populate_products_page'</span> <span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token comment">// here we hook the My Account menu links and add our custom one</span>
<span class="token keyword">function</span> <span class="token function-definition function">misha_purchased_products_link</span><span class="token punctuation">(</span> <span class="token variable">$menu_links</span> <span class="token punctuation">)</span><span class="token punctuation">{</span>

	<span class="token comment">// we use array_slice() because we want our link to be on the 3rd position</span>
	<span class="token keyword">return</span> <span class="token function">array_slice</span><span class="token punctuation">(</span> <span class="token variable">$menu_links</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token constant boolean">true</span> <span class="token punctuation">)</span>
	<span class="token operator">+</span> <span class="token keyword">array</span><span class="token punctuation">(</span> <span class="token string single-quoted-string">'purchased-products'</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'Purchased Products'</span> <span class="token punctuation">)</span>
	<span class="token operator">+</span> <span class="token function">array_slice</span><span class="token punctuation">(</span> <span class="token variable">$menu_links</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token constant">NULL</span><span class="token punctuation">,</span> <span class="token constant boolean">true</span> <span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token punctuation">}</span>

<span class="token comment">// here we register our rewrite rule</span>
<span class="token keyword">function</span> <span class="token function-definition function">misha_add_products_endpoint</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
	<span class="token function">add_rewrite_endpoint</span><span class="token punctuation">(</span> <span class="token string single-quoted-string">'purchased-products'</span><span class="token punctuation">,</span> <span class="token constant">EP_PAGES</span> <span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token comment">// here we populate the new page with the content</span>
<span class="token keyword">function</span> <span class="token function-definition function">misha_populate_products_page</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>

	<span class="token keyword">global</span> <span class="token variable">$wpdb</span><span class="token punctuation">;</span>

	<span class="token comment">// this SQL query allows to get all the products purchased by the current user</span>
	<span class="token comment">// in this example we sort products by date but you can reorder them another way</span>
	<span class="token variable">$purchased_products_ids</span> <span class="token operator">=</span> <span class="token variable">$wpdb</span><span class="token operator">-></span><span class="token function">get_col</span><span class="token punctuation">(</span> <span class="token variable">$wpdb</span><span class="token operator">-></span><span class="token function">prepare</span><span class="token punctuation">(</span>
		<span class="token string double-quoted-string">"
		SELECT      itemmeta.meta_value
		FROM        "</span> <span class="token operator">.</span> <span class="token variable">$wpdb</span><span class="token operator">-></span><span class="token property">prefix</span> <span class="token operator">.</span> <span class="token string double-quoted-string">"woocommerce_order_itemmeta itemmeta
		INNER JOIN  "</span> <span class="token operator">.</span> <span class="token variable">$wpdb</span><span class="token operator">-></span><span class="token property">prefix</span> <span class="token operator">.</span> <span class="token string double-quoted-string">"woocommerce_order_items items
		            ON itemmeta.order_item_id = items.order_item_id
		INNER JOIN  <span class="token interpolation"><span class="token variable">$wpdb</span><span class="token operator">-></span><span class="token property">posts</span></span> orders
		            ON orders.ID = items.order_id
		INNER JOIN  <span class="token interpolation"><span class="token variable">$wpdb</span><span class="token operator">-></span><span class="token property">postmeta</span></span> ordermeta
		            ON orders.ID = ordermeta.post_id
		WHERE       itemmeta.meta_key = '_product_id'
		            AND ordermeta.meta_key = '_customer_user'
		            AND ordermeta.meta_value = %s
		ORDER BY    orders.post_date DESC
		"</span><span class="token punctuation">,</span>
		<span class="token function">get_current_user_id</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	<span class="token punctuation">)</span> <span class="token punctuation">)</span><span class="token punctuation">;</span>

	<span class="token comment">// some orders may contain the same product, but we do not need it twice</span>
	<span class="token variable">$purchased_products_ids</span> <span class="token operator">=</span> <span class="token function">array_unique</span><span class="token punctuation">(</span> <span class="token variable">$purchased_products_ids</span> <span class="token punctuation">)</span><span class="token punctuation">;</span>

	<span class="token comment">// if the customer purchased something</span>
	<span class="token keyword">if</span><span class="token punctuation">(</span> <span class="token operator">!</span><span class="token keyword">empty</span><span class="token punctuation">(</span> <span class="token variable">$purchased_products_ids</span> <span class="token punctuation">)</span> <span class="token punctuation">)</span> <span class="token punctuation">:</span>

		<span class="token comment">// it is time for a regular WP_Query</span>
		<span class="token variable">$purchased_products</span> <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">WP_Query</span><span class="token punctuation">(</span> <span class="token keyword">array</span><span class="token punctuation">(</span>
			<span class="token string single-quoted-string">'post_type'</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'product'</span><span class="token punctuation">,</span>
			<span class="token string single-quoted-string">'post_status'</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'publish'</span><span class="token punctuation">,</span>
			<span class="token string single-quoted-string">'post__in'</span> <span class="token operator">=></span> <span class="token variable">$purchased_products_ids</span><span class="token punctuation">,</span>
			<span class="token string single-quoted-string">'orderby'</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'post__in'</span>
		<span class="token punctuation">)</span> <span class="token punctuation">)</span><span class="token punctuation">;</span>

		<span class="token keyword">echo</span> <span class="token string single-quoted-string">''</span><span class="token punctuation">;</span>

		<span class="token function">woocommerce_product_loop_start</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

		<span class="token keyword">while</span> <span class="token punctuation">(</span> <span class="token variable">$purchased_products</span><span class="token operator">-></span><span class="token function">have_posts</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">)</span> <span class="token punctuation">:</span> <span class="token variable">$purchased_products</span><span class="token operator">-></span><span class="token function">the_post</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

			<span class="token function">wc_get_template_part</span><span class="token punctuation">(</span> <span class="token string single-quoted-string">'content'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'product'</span> <span class="token punctuation">)</span><span class="token punctuation">;</span>

		<span class="token keyword">endwhile</span><span class="token punctuation">;</span>

		<span class="token function">woocommerce_product_loop_end</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

		<span class="token function">woocommerce_reset_loop</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token function">wp_reset_postdata</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

		<span class="token keyword">echo</span> <span class="token string single-quoted-string">''</span><span class="token punctuation">;</span>
	<span class="token keyword">else</span><span class="token punctuation">:</span>
		<span class="token keyword">echo</span> <span class="token string single-quoted-string">'Nothing purchased yet.'</span><span class="token punctuation">;</span>
	<span class="token keyword">endif</span><span class="token punctuation">;</span>

<span class="token punctuation">}</span></code>
0
حسام الدین

سلام این به صورت پیش‌فرض وجود نداره به نظر من افزونه های jetwoobuilder یا woocommerce page builder for elementor رو خریداری کنید و با اون ها صفحه پنل کاربری رو طراحی کنید. ابزارک های مخصوص سفارشات رو هم داره.

لطفا قبل از ارسال پاسخ، این قوانین را مطالعه نمایید:

  • به هیچ عنوان از لینک سایت‌های دیگر یا لینک‌های تبلیغاتی در پاسخ استفاده نکنید.
  • تا حد امکان متن پاسخ کامل و واضح باشد.
  • محتوای پاسخ را از سایت خود یا سایتی دیگر کپی نکنید.

از آنجا که هدف ما ایجاد یک فضای مفید برای همفکری و رسیدن به پاسخ سوالات است، در صورتی که پاسخ شما یکی از شرایط فوق را نداشته باشد، توسط ناظرین تایید نخواهد شد.