programing

WooCommerce에서 정가전 판매가격 표시

css3 2023. 10. 17. 20:26

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);

images

정가보다 세일 가격을 먼저 표시하는 것을 도와주시겠습니까?

다음 후킹 기능 코드는 정가 이전의 판매 가격을 표시합니다.

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