WooCommerce 3에서 프로그래밍 방식으로 제품 가격을 어떻게 변경할 수 있나요?
Dec 08, 2024 am 03:24 AMWooCommerce 3의 후크를 통해 상품 가격 변경
WooCommerce 플랫폼은 상품 가격을 수정할 수 있는 다양한 후크를 제공합니다. add_filter('woocommerce_get_regular_price')와 add_filter('woocommerce_get_price')를 사용해 제시된 솔루션은 단순 상품에는 효과가 있지만, 변형 상품의 경우에는 한계가 있습니다.
변형 상품 가격
변형 상품 가격 조정을 위해 다음과 같이 업데이트된 후크가 있습니다. 권장 사항:
-
단순, 그룹화 및 외부 제품:
- wooCommerce_product_get_price
- wooCommerce_product_get_regular_price
-
변형:
- wooCommerce_product_variation_get_regular_price
- wooCommerce_product_variation_get_price
-
변수 제품 범위:
- woocommerce_variation_prices_price
- woocommerce_variation_prices_regular_price
플러그인 구현
플러그인 내에서 이러한 후크를 구현하려면 다음을 고려하세요.
add_filter('woocommerce_product_get_price', 'custom_price', 99, 2); add_filter('woocommerce_product_get_regular_price', 'custom_price', 99, 2); add_filter('woocommerce_product_variation_get_regular_price', 'custom_price', 99, 2); add_filter('woocommerce_product_variation_get_price', 'custom_price', 99, 2); add_filter('woocommerce_variation_prices_price', 'custom_variable_price', 99, 3); add_filter('woocommerce_variation_prices_regular_price', 'custom_variable_price', 99, 3); function custom_price($price, $product) { $multiplier = 2; // Adjust as needed return (float) $price * $multiplier; } function custom_variable_price($price, $variation, $product) { $multiplier = 2; // Adjust as needed return (float) $price * $multiplier; }
로그인 후 복사
로그인 후 복사
테마 구현
테마를 선호하는 경우 기반 접근 방식을 사용하려면 function.php에 다음 코드를 포함하세요. 파일:
add_filter('woocommerce_product_get_price', 'custom_price', 99, 2); add_filter('woocommerce_product_get_regular_price', 'custom_price', 99, 2); add_filter('woocommerce_product_variation_get_regular_price', 'custom_price', 99, 2); add_filter('woocommerce_product_variation_get_price', 'custom_price', 99, 2); add_filter('woocommerce_variation_prices_price', 'custom_variable_price', 99, 3); add_filter('woocommerce_variation_prices_regular_price', 'custom_variable_price', 99, 3); function custom_price($price, $product) { $multiplier = 2; // Adjust as needed return (float) $price * $multiplier; } function custom_variable_price($price, $variation, $product) { $multiplier = 2; // Adjust as needed return (float) $price * $multiplier; }
로그인 후 복사
로그인 후 복사
추가 참고 사항 및 개선 사항
- 가격 위젯: 가격 필터 위젯 최소값 및 최대값을 조작하려면, 다음 후크 사용을 고려해보세요: woocommerce_price_filter_widget_min_amount 및 woocommerce_price_filter_widget_max_amount.
- 제품 판매 가격: 판매 가격에 대한 특정 후크가 존재합니다: woocommerce_product_get_sale_price, woocommerce_variation_prices_sale_price 및 woocommerce_product_variation_get_sale_price.
- 가격 캐싱: WooCommerce 3에 캐시된 변형 가격을 고려해야 합니다. 가격 캐싱을 효율적으로 처리하려면 add_filter('woocommerce_get_variation_prices_hash') 필터를 사용하는 것이 좋습니다.
위 내용은 WooCommerce 3에서 프로그래밍 방식으로 제품 가격을 어떻게 변경할 수 있나요?의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

인기 기사
2 포인트 박물관 : Bungle Wasteland Location Guide
4 몇 주 전
By 尊渡假赌尊渡假赌尊渡假赌
스플릿 소설을이기는 데 얼마나 걸립니까?
3 몇 주 전
By DDD
Repo : 팀원을 부활시키는 방법
3 몇 주 전
By 尊渡假赌尊渡假赌尊渡假赌
헬로 키티 아일랜드 어드벤처 : 거대한 씨앗을 얻는 방법
3 몇 주 전
By 尊渡假赌尊渡假赌尊渡假赌

핫툴 태그

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

뜨거운 주제
Gmail 이메일의 로그인 입구는 어디에 있나요?
7108
9


자바 튜토리얼
1534
14


라라벨 튜토리얼
1253
25


PHP 튜토리얼
1205
29


Cakephp 튜토리얼
1152
46



Laravel Back End : Part 2, React가있는 React 앱 구축

PHP의 컬 : REST API에서 PHP Curl Extension 사용 방법
