WooCommerce에서 정가전 판매가격 표시
저는 신입회원이고 프로그래머에 약합니다.Sale price를 정가(이미지 첨부) 전에 표시하고 싶습니다.여기 후크가 wocommerce_before_variations_form이라고 판단했습니다.여기 후크에 편집할 코드가 있습니다.
// define the woocommerce_before_variations_form callback
function action_woocommerce_before_variations_form () {
// make action magic happen here ...
};
// add the action
add_action ('woocommerce_before_variations_form', 'action_woocommerce_before_variations_form', 10, 0);
정가보다 세일 가격을 먼저 표시하는 것을 도와주시겠습니까?
다음 후킹 기능 코드는 정가 이전의 판매 가격을 표시합니다.
add_filter( 'woocommerce_format_sale_price', 'invert_formatted_sale_price', 10, 3 );
function invert_formatted_sale_price( $price, $regular_price, $sale_price ) {
return '<ins>' . ( is_numeric( $sale_price ) ? wc_price( $sale_price ) : $sale_price ) . '</ins> <del>' . ( is_numeric( $regular_price ) ? wc_price( $regular_price ) : $regular_price ) . '</del>';
}
코드가 작동합니다.활성 하위 테마(또는 활성 테마)의 php 파일입니다.테스트를 거쳐 작동합니다.
jQuery만 사용하여 이 문제를 해결할 수 있으며 정가와 판매 가격을 표시하는 요소로 스왑할 수 있습니다.
$("#element1").before($("#element2"));
아니면
$("#element1").after($("#element2"));
:)
js fiddle https://jsfiddle.net/nak73406/v9k7b5c1/5/ 에서 한번 더.
언급URL : https://stackoverflow.com/questions/54729888/display-the-sale-price-before-regular-price-in-woocommerce
'programing' 카테고리의 다른 글
외국 키가 있는 경우에만 삭제 (0) | 2023.10.17 |
---|---|
파일 이름을 저장하기 전에 불법 문자를 제거하는 방법? (0) | 2023.10.17 |
동일하지 않은 값에 대한 mysql 구문 (0) | 2023.10.12 |
HTTP에서 HTTPS로의 리디렉션이 AWS ALB에서 작동하지 않음 (0) | 2023.10.12 |
malloc failure는 어떻게 감지합니까? (0) | 2023.10.12 |