Verfasste Forenbeiträge

Ansicht von 2 Antworten - 1 bis 2 (von insgesamt 2)
  • Thread-Starter Adrian

    (@adrianlacheta)

    Ich habe das Experiment jetzt sogar noch drastisch verkleinert. Ich habe in meiner WordPress Installation das Template auf das Standart Template „twentytwentytwo“ umgestellt und hier nur diese eine zusätzliche Template Datei ins Root-Verzeichnis reinkopiert. Um die Installation so clean wie möglich zu bekommen habe ich alle Plugins bis auf WooCommerce deaktiviert.

    Ich verstehe nicht, wieso der Discount immer mit 0,00 € angezeigt wird. Ich vermute, dass das ein WordPress Bug sein könnte.

    <?php
    /*
    Template Name: Gutscheine Übersicht
    */
    get_header();
    
    if (have_posts()):
    while (have_posts()) : the_post();
    ?>
    
    	<h1>Genutzte Gutscheine</h1>
    	
    	<?php		
    	$loop = new WP_Query( array(
    		'post_type'         => 'shop_order',
    		'post_status'       =>  array( 'wc-processing','wc-completed' ),
    		'posts_per_page'    => -1,
    		'fields' 			=> 'ids',
    	));
    	
    	if ( $loop->have_posts() ):
    	while ( $loop->have_posts() ) : $loop->the_post();
    		
    		$order_id = get_the_ID();
    		$order = wc_get_order($order_id);
    
    		$coupons = $order->get_items( 'coupon' );
    		if ( $coupons ) :
    			?>
    			<div class="wc-used-coupons">
    				<ul class="wc_coupon_list">
    					<li><strong><?php esc_html_e( 'Coupon(s)', 'woocommerce' ); ?></strong></li>
    					<?php
    					foreach ( $coupons as $item_id => $item ) :
    						$post_id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_title = %s AND post_type = 'shop_coupon' AND post_status = 'publish' LIMIT 1;", $item->get_code() ) ); // phpcs:disable WordPress.WP.GlobalVariablesOverride.Prohibited
    						$class   = $order->is_editable() ? 'code editable' : 'code';
    						?>
    						<li class="<?php echo esc_attr( $class ); ?>">
    							<?php if ( $post_id ) : ?>
    								<?php
    								$post_url = apply_filters(
    									'woocommerce_admin_order_item_coupon_url',
    									add_query_arg(
    										array(
    											'post'   => $post_id,
    											'action' => 'edit',
    										),
    										admin_url( 'post.php' )
    									),
    									$item,
    									$order
    								);
    								?>
    								<a href="<?php echo esc_url( $post_url ); ?>" class="tips" data-tip="<?php echo esc_attr( wc_price( $item->get_discount(), array( 'currency' => $order->get_currency() ) ) ); ?>">
    									<span><?php echo esc_html( $item->get_code() ); ?></span>
    								</a>
    								<br>
    								<?php echo wc_price( $item->get_discount(), array( 'currency' => $order->get_currency() ) ); ?>
    							<?php else : ?>
    								<span class="tips" data-tip="<?php echo esc_attr( wc_price( $item->get_discount(), array( 'currency' => $order->get_currency() ) ) ); ?>">
    									<span><?php echo esc_html( $item->get_code() ); ?></span>
    								</span>
    							<?php endif; ?>
    							<?php if ( $order->is_editable() ) : ?>
    								<a class="remove-coupon" href="javascript:void(0)" aria-label="Remove" data-code="<?php echo esc_attr( $item->get_code() ); ?>"></a>
    							<?php endif; ?>
    						</li>
    					<?php endforeach; ?>
    				</ul>
    			</div>
    		<?php endif;
    	endwhile;
    	wp_reset_postdata();
    	endif;
    	
    endwhile;
    endif;
    get_footer();
    ?>

    Das ist meine Ausgabe:

    Coupon(s)
    a76c7775a918352efa
    0,00 €
    Coupon(s)
    4161576ecec13a2814
    0,00 €
    Coupon(s)
    a76c7775a918352efa
    0,00 €
    Coupon(s)
    vipdrink2022
    0,00 €
    4161576ecec13a2814
    0,00 €
    Thread-Starter Adrian

    (@adrianlacheta)

    Hi Michi,

    dank dir, das ist exakt die Stelle und im Backend wird der richtige discount angezeigt. Aber wenn ich versuche daraus einen eigenen WP_Query zu machen, dann ist der discount amount immer bei 0,00 €. Ich hab den Code etwas abgeändert, damit der ToolTip einfach ausgegeben wird.

    $loop = new WP_Query( array(
    	'post_type'         => 'shop_order',
    	'post_status'       =>  array( 'wc-processing','wc-completed' ),
    	'posts_per_page'    => -1,
    	'fields' 			=> 'ids',
    ));
    
    if ( $loop->have_posts() ):
    while ( $loop->have_posts() ) : $loop->the_post();
    	
    	$order_id = get_the_ID();
    	$order = wc_get_order($order_id);
    
    	$coupons = $order->get_items( 'coupon' );
    	if ( $coupons ) :
    		?>
    		<div class="wc-used-coupons">
    			<ul class="wc_coupon_list">
    				<li><strong><?php esc_html_e( 'Coupon(s)', 'woocommerce' ); ?></strong></li>
    				<?php
    				foreach ( $coupons as $item_id => $item ) :
    					$post_id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_title = %s AND post_type = 'shop_coupon' AND post_status = 'publish' LIMIT 1;", $item->get_code() ) ); // phpcs:disable WordPress.WP.GlobalVariablesOverride.Prohibited
    					$class   = $order->is_editable() ? 'code editable' : 'code';
    					?>
    					<li class="<?php echo esc_attr( $class ); ?>">
    						<?php if ( $post_id ) : ?>
    							<?php
    							$post_url = apply_filters(
    								'woocommerce_admin_order_item_coupon_url',
    								add_query_arg(
    									array(
    										'post'   => $post_id,
    										'action' => 'edit',
    									),
    									admin_url( 'post.php' )
    								),
    								$item,
    								$order
    							);
    							?>
    							<a href="<?php echo esc_url( $post_url ); ?>" class="tips" data-tip="<?php echo esc_attr( wc_price( $item->get_discount(), array( 'currency' => $order->get_currency() ) ) ); ?>">
    								<span><?php echo esc_html( $item->get_code() ); ?></span>
    							</a>
    							<br>
    							<?php echo wc_price( $item->get_discount(), array( 'currency' => $order->get_currency() ) ); ?>
    						<?php else : ?>
    							<span class="tips" data-tip="<?php echo esc_attr( wc_price( $item->get_discount(), array( 'currency' => $order->get_currency() ) ) ); ?>">
    								<span><?php echo esc_html( $item->get_code() ); ?></span>
    							</span>
    						<?php endif; ?>
    						<?php if ( $order->is_editable() ) : ?>
    							<a class="remove-coupon" href="javascript:void(0)" aria-label="Remove" data-code="<?php echo esc_attr( $item->get_code() ); ?>"></a>
    						<?php endif; ?>
    					</li>
    				<?php endforeach; ?>
    			</ul>
    		</div>
    	<?php endif; 
    
    	
    	
    	
    endwhile;
    wp_reset_postdata();
    endif;

    Das ist meine Ausgabe:

    Coupon(s)
    a76c7775a918352efa
    0,00 €
    Coupon(s)
    4161576ecec13a2814
    0,00 €
    Coupon(s)
    a76c7775a918352efa
    0,00 €
    Coupon(s)
    vipdrink2022
    0,00 €
    4161576ecec13a2814
    0,00 €
    • Diese Antwort wurde geändert vor 1 Jahr, 9 Monaten von Adrian.
Ansicht von 2 Antworten - 1 bis 2 (von insgesamt 2)