• Resolved westbrasil

    (@westbrasil)


    Hi!

    Is possible to create a Export button that can be clicked to generate a report of all orders for a product in whatever product is in vogue, such as woocommerce reports, product page, sales environment like WCFM, DOKAN, etc …?

    Like this:

    add_filter( 'post_row_actions', function($actions, $post){
    	if ( 'product' == $post->post_type ) {
    		$actions['export_orders'] = '<a href="' . wp_nonce_url( admin_url( 'edit.php?post_type=product&action=export_orders&post=' . $post->ID ), 'export-orders-product_' . $post->ID ) 
    							. '" rel="permalink">' . esc_html__( 'Export Orders', 'woocommerce' ) . '</a>';
    	}
    	return $actions;
    }, 100, 2 );
    
    add_action( 'admin_action_export_orders', function() {
    	$product_id = $_REQUEST['post'];
    	add_filter('woe_settings_validate_defaults', function($settings) use ($product_id){
    		$settings['products'] = array($product_id);
    		$settings['all_products_from_order'] = 0;// set 1  to export all items from the order!
    		return $settings;
    	});	
    	
    	$_REQUEST['profile'] = 'now';
    	$ajax_export = new WC_Order_Export_Ajax();
    	$ajax_export->ajax_run_one_job();
        die();	
    });

    If not possible,
    This link structure (/wp-admin/edit.php?post_type=product&action=export_orders&post=—ID—) could be used in the frontend by set permission?

    or, like this:

    <form method="get" action="/wp-admin/admin-ajax.php">
    <input type="hidden" name="action" value="order_exporter">
    <input type="hidden" name="method" value="run_one_job">
    <input type="hidden" name="profile" value="now">
        <input type="submit" name="exportAllOrders" id="exportAllOrders" value="Export">
    </form>

    But in ID, exportAllOrders changes to product-id, allowing a button to export orders by product in any place…

    Technically a button that can be clicked to generate a report in any place…

    Thanks

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author algol.plus

    (@algolplus)

    Hello

    You can remove call of function “wp_nonce_url” from url and just use url at any page

    admin_url( 'edit.php?post_type=product&action=export_orders&post=' . $post->ID )

    in my code, $post->ID is product ID

    • This reply was modified 6 years, 3 months ago by algol.plus.
    Thread Starter westbrasil

    (@westbrasil)

    Thanks for reply,
    I dont understand: if I remove wp_nonce_url a error occured. but if a alternate URL to something like: admin_url( ‘?post_type=product&action=export_orders&post=’ . $post->ID ) and create a button nothing happen. I dont export in frontend or any other place.

    This link structure (/wp-admin/edit.php?post_type=product&action=export_orders&post=—ID—) could be used in the frontend like a simple edit?

    Sorry, i didn’t understand how i can use it in other places or edit function.

    For example, this function provide a link Export (Export Button) in a backend and frontend or any other place. Or… a form to submit a export.

    Or, what the permission for that?

    • This reply was modified 6 years, 3 months ago by westbrasil.
    • This reply was modified 6 years, 3 months ago by westbrasil.
    Plugin Author algol.plus

    (@algolplus)

    Hello

    Following code works ok, but only for admins who have access to /wp-admin!

    if you want something different – you should code custom ajax handler.

    //add link below product price, for admin
    add_action( 'woocommerce_single_product_summary', function(){
    	global $post;
      
    	if( is_super_admin() )
    		echo '<a href="' . wp_nonce_url( admin_url( 'edit.php?post_type=product&action=export_orders&post=' . $post->ID ), 'export-orders-product_' . $post->ID ) 
    							. '" rel="permalink">' . esc_html__( 'Export Orders', 'woocommerce' ) . '</a>';
    } );
    
    add_action( 'admin_action_export_orders', function() {
    	$product_id = $_REQUEST['post'];
    	add_filter('woe_settings_validate_defaults', function($settings) use ($product_id){
    		$settings['products'] = array($product_id);
    		$settings['all_products_from_order'] = 0;// set 1  to export all items from the order!
    		return $settings;
    	});	
    	
    	$_REQUEST['profile'] = 'now';
    	$ajax_export = new WC_Order_Export_Ajax();
    	$ajax_export->ajax_run_one_job();
        die();	
    });
    Thread Starter westbrasil

    (@westbrasil)

    Thanks for reply
    If I edit code for call ajax-admin nothing happen,

    if( is_super_admin() )
    		echo '<a href="' . wp_nonce_url( admin_url( 'edit.php?post_type=product&action=export_orders&post=' . $post->ID ), 'export-orders-product_' . $post->ID ) 
    							. '" rel="permalink">' . esc_html__( 'Export Orders', 'woocommerce' ) . '</a>';
    } );

    to

    ‘?post_type=product&action=export_orders&post=’ . $post->ID ), ‘export-orders-product_’ . $post->ID )
    . ‘” rel=”permalink”>’ . esc_html__( ‘Export Orders’, ‘woocommerce’ ) . ‘‘;
    } );`

    or

    ‘ajax-admin?post_type=product&action=export_orders&post=’ . $post->ID ), ‘export-orders-product_’ . $post->ID )
    . ‘” rel=”permalink”>’ . esc_html__( ‘Export Orders’, ‘woocommerce’ ) . ‘</a>’;
    } );`

    If I set permission to access link generated (mysite.com/wp-admin/edit.php?post_type=product&action=export_orders&post=10 ) is possible to generate export for another user roles, like managers, sellers, etc?

    Thanks

    Plugin Author algol.plus

    (@algolplus)

    Hello

    Please, don’t edit my code. This code will work only for admins.

    You should hire WordPress/PHP programmer to code custom ajax handler.
    I’m sorry, I can’t help you more .
    But your programmer can contact me via helpdesk.

    Alex

    Thread Starter westbrasil

    (@westbrasil)

    We have no professional programmer so far.
    Thanks for listening us!

    Plugin Author algol.plus

    (@algolplus)

    yes, I understand it.
    but these changes require a lot of time, so you have to hire someone else.

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Export button by product’ is closed to new replies.