carbon-fields icon indicating copy to clipboard operation
carbon-fields copied to clipboard

Carbon Fields + WooCommerce

Open kazztor- opened this issue 5 years ago • 3 comments

Version

  • Carbon Fields: 3.1
  • WordPress: 5.3.2
  • PHP: 7.2.24
  • WooCommerce: 3.8.1

Expected Behavior

Show Images on front page (WooCommerce shop)

Actual Behavior

Images are not shown

Container definition


use Carbon_Fields\Field;
use Carbon_Fields\Container;

add_action( 'carbon_fields_register_fields', 'crb_attach_post_meta' );
function crb_attach_post_meta() {
    Container::make( 'post_meta', __( 'Page Options' ) )
 			->where( 'post_id', 'IN', array(6,2) ) //front page & Sampe Page
			->add_fields( array(

            Field::make( 'complex', 'crb_slides', 'Slides' )
                ->set_layout( 'tabbed-horizontal' )
                ->add_fields( array(
                    Field::make( 'image', 'image', 'Image' ),
                ) ),
		) );
}


function display_slider() {


$slides = carbon_get_the_post_meta( 'crb_slides' );
echo "test";
echo '<ul>';
foreach ( $slides as $slide ) {
    echo '<li>';
    echo wp_get_attachment_image( $slide['image'] );
    echo '</li>';
}
echo '</ul>';


}
add_action( 'woocommerce_before_main_content', 'display_slider' );
add_action( 'tha_entry_top', 'display_slider' );  //Theme Hook Alliance

Steps to Reproduce the Problem

  1. add images
  2. load pages

Comments

fresh WordPress & WooCommerce install the same function is running on two different pages (WooCommerce front-page/shop and Sample Page) but the images are only shown on the Sample Page. No images are displayed on front-page/shop

FRONT PAGE front-page SAMPLE PAGE sample-page

kazztor- avatar Jan 02 '20 06:01 kazztor-

Hi @kazztor-

I guess that you aren't in the context of a page when trying to get the images.

Can you output get_the_ID() and let me know what it prints out?

jorostoyanov avatar Jan 02 '20 08:01 jorostoyanov

I'm getting a different ID for the shop/front-page which is '6' in the editor but get_the_ID() shows '23'.

kazztor- avatar Jan 02 '20 16:01 kazztor-

The Shop page is actually a Taxonomy Archive for Products, which is perhaps why passing the page ID does not work.

tamara-m avatar Jul 11 '22 21:07 tamara-m