• I am working with WC sales report email plugin and trying to add new rows in report email.

    Currently it is showing 5 rows as :
    1- Total Sign Ups
    2- Total Orders
    3- Total Items
    4- Sales in this period
    5- Top Sellers

    Now i want to add new 2 fields:

    1- Total Shipping for the specified period
    2- Net Sales in the specified period

    I have created the two new templates same as the other rows and add the code for shipping row as follows:

    class WC_SRE_Row_Total_Sales extends WC_SRE_Report_Row {
    
    	/**
    	 * The constructor
    	 *
    	 * @param $date_range
    	 *
    	 * @access public
    	 * @since  1.0.0
    	 */
    	public function __construct( $date_range ) {
    		parent::__construct( $date_range, 'total_shipping', __( 'Shipping in this period', 'woocommerce-sales-report-email' ) );
    	}
    
    	/**
    	 * Prepare the data
    	 *
    	 * @access public
    	 * @since  1.0.0
    	 */
    	public function prepare() {
    
    		// Create a Report Manager object
    		$report_manager = new WC_SRE_Report_Manager( $this->get_date_range() );
    
    		// Get the total sales
    		$total_shipping = $report_manager->get_order_report_data( array(
    			'data'         => array(
    				'_order_total' => array(
    					'type'     => 'meta',
    					'function' => 'SUM',
    					'name'     => 'total_shipping'
    				),
    			),
    			'query_type'   => 'get_var',
    			'filter_range' => true
    		) );
    
    		// Set the value
            echo $total_shipping. "Test";
    		$this->set_value( wc_price( $total_shipping ) );
    	}
    
    }

    Also i have get this row in the email file as:

    // Create the date range object
    		$date_range = new WC_SRE_Date_Range( WC_SRE_Options::get_interval() );
    
    		// Add the elements
    		$this->rows = array(
    			new WC_SRE_Row_Total_Sign_Ups( $date_range ),
    			new WC_SRE_Row_Total_Orders( $date_range ),
    			new WC_SRE_Row_Total_Items( $date_range ),
    			new WC_SRE_Row_Total_Sales( $date_range ),
    			new WC_SRE_Row_Top_Sellers( $date_range ),
                new WC_SRE_Row_Gross_Sales( $date_range ),
                new WC_SRE_Row_Total_Shipping( $date_range ),
                new WC_SRE_Row_Net_Sales( $date_range ),
    		);

    Now i want to know is it good approach it will work or not

  • The topic ‘How to add new rows in WC sales report email’ is closed to new replies.