• The cart is not an accurate representation of the order total without taxes and shipping costs. How can we make sure the user has billing and shipping addresses in their WooCommerce customer data before they can download the cart?

Viewing 1 replies (of 1 total)
  • Plugin Author David Jensen

    (@dkjensen)

    Hello

    You would need to render the download cart as PDF button conditionally based on whether the customer has entered their billing and shipping information on checkout. Something like the following:

    add_action( 'woocommerce_proceed_to_checkout', function() {
    	$current_user_id = get_current_user_id();
    
    	if ( $current_user_id ) {
    		$customer = new WC_Customer( $current_user_id );
    
    		$billing_address_1  = $customer->get_billing_address_1();
    		$shipping_address_1 = $customer->get_shipping_address_1();
    
    		if ( ! empty( $billing_address_1 ) && ! empty( $shipping_address_1 ) ) {
    			?>
    
    			<a href="<?php echo esc_url( wp_nonce_url( add_query_arg( array( 'cart-pdf' => '1' ), wc_get_cart_url() ), 'cart-pdf' ) ); ?>" class="cart-pdf-button button" target="_blank">
    				<?php echo esc_html( get_option( 'wc_cart_pdf_button_label', __( 'Download Cart as PDF', 'wc-cart-pdf' ) ) ); ?>
    			</a>
    
    			<?php
    		} else {
    			?>
    
    			<p><?php esc_html_e( 'Please enter your billing and shipping information on checkout to download cart as PDF.' ); ?></p>
    
    			<?php
    		}
    	}
    } );
Viewing 1 replies (of 1 total)
  • The topic ‘Require Billing and Shipping Addresses before download’ is closed to new replies.