• Hi guys i have two question:
    1. It possible to add automatically photo and description of woocommerce products in the quote??
    2. The plugins when I created quotes adds automatically wordpress users like this name:
    Blank-Name-1010P50u
    Blank-Name-7387.Wm
    Blank-Name-7387.Wm
    You know why?

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Hello there

    I think you may use the following code as a reference and adapt it to your requirements in order to create the invoices programmatically.

    function sliced_create_invoice_programmatically_example() {
    	
    	/**
    	 * 1) Invoices are stored as Custom Post Type 'sliced_invoice'.
    	 * Let's start by creating a new post:
    	 */
    	$args = array(
    		'post_title'      => 'Example Invoice Title',
    		'post_content'    => 'Description here',
    		'post_author'     => get_current_user_id(),
    		'post_status'     => 'publish',
    		'post_type'       => 'sliced_invoice',
    	);
    	$invoice_id = wp_insert_post( $args );
    	
    	/**
    	 * 2) now let's attach some extra pieces of information.
    	 * These are stored as post metas:
    	 */
    	// MOST IMPORTANT, the user ID of the client the invoice is associated with:
    	update_post_meta( $invoice_id, '_sliced_client', 1 ); // example: user ID "1"
    	
    	// invoice created date:
    	update_post_meta( $invoice_id, '_sliced_invoice_created', time() ); // example: now
    	
    	// invoice due date:
    	update_post_meta( $invoice_id, '_sliced_invoice_due', date( "U", strtotime( "2018-12-31" ) ) ); // example: Dec. 31, 2018
    	
    	// invoice number:
    	update_post_meta( $invoice_id, '_sliced_invoice_number', sliced_get_next_invoice_number() );
    	Sliced_Invoice::update_invoice_number( $invoice_id ); // advance invoice number for the next time
    	
    	// automatically enable your chosen payment methods:
    	$payment_methods = sliced_get_accepted_payment_methods();
    	update_post_meta( $invoice_id, '_sliced_payment_methods', array_keys($payment_methods) );
    	
    	// let's put in some line items:
    	$line_items = array(
    		array( 
    			'qty'     => '1',
    			'title'   => 'Test item',
    			'amount'  => '100',
    			'taxable' => 'on', // taxable
    		),
    		array( 
    			'qty'     => '1',
    			'title'   => 'Another test item',
    			'amount'  => '20',
    			'taxable' => false, // not taxable
    		),
    	);
    	update_post_meta( $invoice_id, '_sliced_items', $line_items );
    	
    	// set status as draft:
    	Sliced_Invoice::set_as_draft( $invoice_id );
    	
    	// anything else you want to add here...
    	
    
    	/**
    	 * That's it!
    	 */
    	return $invoice_id;
    	
    }
    
    // 'init' is a good place to hook into.
    // The Sliced Invoices plugin will be fully loaded by this point:
    add_action( 'init', 'sliced_create_invoice_programmatically_example' );

    My best,
    Andrew

Viewing 1 replies (of 1 total)
  • The topic ‘Add Automatically Photo & Description of woocommerce product’ is closed to new replies.