반응형
Woocommerce에서 제품 이름 가져오기
PHP를 사용하여 제품명을 제품 ID로 에코함으로써 제품 제목을 표시할 수 있도록 하고 싶습니다(제품 페이지 자체가 아닌 페이지 내에 표시되도록 합니다).워드프레스를 사용하고 있으며 PHP용 플러그인이 있기 때문에 PHP 코드를 포함할 수 있습니다.[php]echo 'example';[/php]
제품의 예로는 http://ukcctvinstallations.co.uk/product/1-camera-residential-system-hi-res/가 있습니다.
상품을 편집하면 URL에 'Post' = 129라고 표시되어 있는데, 이것이 상품 ID라고 하는 것이 맞습니까?
누군가 이에 대한 해결책을 가지고 있다면 매우 감사하겠습니다.저는 WooCommerce를 사용하고 있습니다.
제품을 개체로 받는다고 가정합니다.
$product = wc_get_product( id );
echo $product->get_title();
(WC 버전 2.5.2)
솔루션을 찾았습니다.-
echo get_the_title( 'ID' );
여기를 봐주세요.http://docs.woothemes.com/wc-apidocs/package-WooCommerce.Functions.Product.html
2017 - 2020 - WooCommerce 3부터WC_Product
방법get_name()
global $product;
// If the WC_product Object is not defined globally
if ( ! is_a( $product, 'WC_Product' ) ) {
$product = wc_get_product( get_the_id() );
}
echo $product->get_name();
카트 항목:
foreach( WC()->cart->get_cart() as $cart_item ) {
echo $cart_item['data']->get_name();
}
주문시 아이템:
foreach( $order->get_items() as $cart_item ) {
echo $item->get_name();
// Or
$product = $item->get_product(); // Get the WC_Product Object
echo $product->get_name();
}
다음은 제 CCTV 워드프레스 사이트의 페이지에서 가져온 PHP 코드입니다.
<header class="entry-header">
<?php
if ( is_singular() ) :
the_title( '<h1 class="entry-title">', '</h1>' );
else :
the_title( sprintf( '<h2 class="entry-title"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h2>' );
endif;
?>
언급URL : https://stackoverflow.com/questions/26167916/get-the-product-name-in-woocommerce
반응형
'programing' 카테고리의 다른 글
복잡하지만 "표준" 웹 앱에 php 프레임워크 대신 Wordpress를 사용하면 무엇을 잃게 됩니까?트레이드오프가 가치가 있을까요? (0) | 2023.03.13 |
---|---|
여러 행을 한 행에 집약하는 Oracle SQL 쿼리가 있습니까? (0) | 2023.03.13 |
각도(angular)를 사용하여 ng-module 내부의 htmlJS (0) | 2023.03.13 |
로그인 페이지로 각도 리다이렉트 (0) | 2023.03.13 |
모든 엔트리를 한 번에 무한 스크롤로 로드하여 python의 HTML을 구문 분석하는 방법 (0) | 2023.03.13 |